title: How to plot data from QTableWidget into QChart
body: <p>I'm working on data analysis software, which takes data from remote database and puts it into <em>QTableWidget</em>. How could I effectively get these data from table and put them into <em>QChart</em>?</p>
  
  <p>I've seen that if I had been using <em>QTableView</em>, it could have been done with models, but as I understand it, using <em>QTableView</em> would be far more complicated for my scenario.</p>
  
  <pre><code>from PySide2.QtWidgets import *
  from PySide2.QtGui import *
  from PySide2.QtCore import *
  from PySide2.QtCharts import *
  import sys
  import random
  
  
  class DateTimeDelegate(QStyledItemDelegate):
      def initStyleOption(self, option, index):
          super(DateTimeDelegate, self).initStyleOption(option, index)
          value = index.data()
          option.text = 
  QDateTime.fromMSecsSinceEpoch(value).toString("dd.MM.yyyy")
  
  
  class MainWindow(QMainWindow):
      def __init__(self):
          super(MainWindow, self).__init__()
  
          self.setGeometry(0, 0, 1280, 400)
          self.chart_table()
  
          self.populate()
      def chart_table(self):
          self.table = QTableWidget(0, 2)
          delegate = DateTimeDelegate(self.table)
          self.table.setItemDelegateForColumn(0, delegate)
          chart = QtCharts.QChart()
          self.chartView = QtCharts.QChartView(chart)
          self.chartView.setFixedSize(600, 430)
  
          splitter = QSplitter(self)
          splitter.addWidget(self.table)
          splitter.addWidget(self.chartView)
  
          self.setCentralWidget(splitter)
  
          series = QtCharts.QLineSeries(name='Odoslané')
          mapper = QtCharts.QVXYModelMapper(xColumn=0, yColumn=2)
          mapper.setModel(self.table.model())
          mapper.setSeries(series)
          chart.addSeries(mapper.series())
  
          self.axis_X = QtCharts.QDateTimeAxis()
          self.axis_X.setFormat("MMM yyyy")
          self.axis_Y = QtCharts.QValueAxis()
  
          chart.setAxisX(self.axis_X, series)
          chart.setAxisY(self.axis_Y, series)
          self.axis_Y.setRange(0, 0)
          self.axis_Y.setLabelFormat('%.0f')
          self.axis_X.setRange(QDate(2017, 10, 1), QDate.currentDate())
  
          chart.setTitle('Chart')
  
      def addRow(self, dt, value):
          self.table.insertRow(0)
  
          for col, v in enumerate((dt.toMSecsSinceEpoch(), value)):
              it = QTableWidgetItem()
              it.setData(Qt.DisplayRole, dt.toMSecsSinceEpoch())
              self.table.setItem(0, 0, it)
          t_m, t_M = self.axis_X.min(), self.axis_X.max()
          t_m = min(t_m, dt)
          t_M = max(t_M, dt)
  
          m, M = self.axis_Y.min(), self.axis_Y.max()
          m = min(m, value)
          M = max(M, value)
  </code></pre>
  
  <p>In this method I simulate filling table with data as I get them from database.</p>
  
  <pre><code>def populate(self):
      for i in range(4):
          count=random.randint(1,40)
          value_str = QDate.currentDate().addDays(count).toString('dd.MM.yyyy')
  
          dt = QDateTime.fromString(value_str, "dd.MM.yyyy")
  
          sent = QTableWidgetItem(str(count))
          value = int(sent.text())
  
          self.addRow(dt, value)
          self.table.setItem(0, 1, sent)
  </code></pre>
  
  <p>And App running function - </p>
  
  <pre><code>def main():
      app = QApplication(sys.argv)
      gui = MainWindow()
      gui.show()
      sys.exit(app.exec_())
  
  main()
  </code></pre>