当前位置:   article > 正文

pyside2嵌入html显示pyecharts图_pyside echart qwebengineview

pyside echart qwebengineview


py文件代码

  1. import os
  2. import numpy as np
  3. import pandas as pd
  4. import pyecharts.options as opts
  5. from pyecharts.charts import Line
  6. from PySide2 import QtCore
  7. from PySide2.QtCore import QDir, QFile, QObject, Qt
  8. from PySide2.QtGui import QIcon
  9. from PySide2.QtUiTools import QUiLoader
  10. from PySide2.QtWebEngineWidgets import QWebEngineView
  11. from PySide2.QtWidgets import (QAbstractItemView, QApplication, QCheckBox,
  12. QDialog, QDoubleSpinBox, QFileDialog,
  13. QFileSystemModel, QFormLayout, QInputDialog,
  14. QLabel, QLayout, QLineEdit, QMessageBox,
  15. QPlainTextEdit, QPushButton, QStyle, QTableView,
  16. QTreeView, QVBoxLayout, QWidget)
  17. # pyinstaller s.spec
  18. class gui(QObject):
  19. def __init__(self):
  20. QObject.__init__(self)
  21. qfile_gui = QFile('to_bridges.ui')
  22. qfile_gui.open(QFile.ReadOnly)
  23. self.ui = QUiLoader().load(qfile_gui)
  24. self.ui.pushButton.clicked.connect(self.plot)
  25. def plot(self):
  26. x = ['440', '500', '675', '870', '1020']
  27. y1 = [0.631, 0.673, 0.62, 0.481, 0.469]
  28. y15 = [0.108, 0.14, 0.172, 0.131, 0.181]
  29. lab = ['1', '15']
  30. w = self.ui.scrollArea.width()
  31. h = self.ui.scrollArea.height()
  32. li = (Line(
  33. init_opts=opts.InitOpts(width=str(w) + "px",
  34. height=str(h) +
  35. 'px')).add_xaxis(x))
  36. for i, d in zip(lab, [y1, y15]):
  37. li = li.add_yaxis(i, d)
  38. #设置浏览器网页为pyecharts图
  39. bro = QWebEngineView()
  40. bro.setHtml(li.render_embed())
  41. self.ui.scrollArea.setWidget(bro)
  42. app = QApplication([])
  43. stats = gui()
  44. app.setWindowIcon(QIcon('./resource/icon.ico'))
  45. stats.ui.show()
  46. app.exec_()

ui文件的设计界面如下

使用scrollarea作为容器存放浏览器


显示效果如下

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/165087
推荐阅读
相关标签
  

闽ICP备14008679号