|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
各位大神求助!!!
本人想在局域网的环境下编一个pyecharts生成的应用。
但pyecharts生成的html文件都是基于浏览器打开的,
之前用"render_embed()",发现可以打包成功,但打开应用是空白。
之后尝试用“render()”,还是不能成功。
穷途末路,在此求教网络上的大神帮忙解决!
代码如下:
- import sys,os
- from PySide2 import QtCore
- from PySide2 import QtWidgets
- from PySide2.QtGui import *
- from PySide2.QtCore import *
- from pyecharts.charts import Bar
- from PySide2.QtWidgets import *
- from pyecharts import options as opts
- from PySide2.QtUiTools import QUiLoader
- from pyecharts.globals import CurrentConfig
- from PySide2.QtWebEngineWidgets import QWebEngineView
- from ui_14 import * #Pyside2生成的py文件
- class Form(QWidget, Ui_Form):
- def __init__(self, parent = None):
- CurrentConfig.ONLINE_HOST = os.getcwd()+'/'+'pyecharts/pyecharts-assets/assets/'
- ## # os.getcwd() 返回当前文件路径
- super(Form, self).__init__(parent) # 调用父类的方法
- self.setupUi(self)
-
- x = [ 'a1','b1','c1' ]
- y1 = [ 1240,524,270 ]
- y2 = [1300,300,530]
- bar = Bar(init_opts=opts.InitOpts(width=str(500) + "px",height=str(400) +'px'))
- ## bar = Bar(init_opts=opts.InitOpts())
- bar.add_xaxis(xaxis_data=x)
- bar.add_yaxis(series_name='A',y_axis=y1)
- bar.add_yaxis(series_name='B',y_axis=y2)
- bar.set_global_opts(title_opts=opts.TitleOpts(title='示例'))
-
- bro = QWebEngineView()
- html_path=os.getcwd()+'/'+'chart22.html'
- bar.render(html_path)
- bro.setUrl(QUrl(html_path.replace('\\','/')))
- self.scrollArea.setWidget(bro)
- print()
-
- if __name__ == "__main__":
- app = QtWidgets.QApplication(sys.argv)
- widget = Form()
- widget.show()
- sys.exit(app.exec_())
复制代码
上面代码中的ui_14.py文件代码如下:
- import sys,os
- from PySide2 import QtCore
- from PySide2 import QtWidgets
- from PySide2.QtGui import *
- from PySide2.QtCore import *
- from pyecharts.charts import Bar
- from PySide2.QtWidgets import *
- from pyecharts import options as opts
- from PySide2.QtUiTools import QUiLoader
- from pyecharts.globals import CurrentConfig
- from PySide2.QtWebEngineWidgets import QWebEngineView
- from ui_14 import *
- class Form(QWidget, Ui_Form):
- def __init__(self, parent = None):
- CurrentConfig.ONLINE_HOST = os.getcwd()+'/'+'pyecharts/pyecharts-assets/assets/'
- ## # os.getcwd() 返回当前文件路径
- super(Form, self).__init__(parent) # 调用父类的方法
- self.setupUi(self)
-
- x = [ 'a1','b1','c1' ]
- y1 = [ 1240,524,270 ]
- y2 = [1300,300,530]
- bar = Bar(init_opts=opts.InitOpts(width=str(500) + "px",height=str(400) +'px'))
- ## bar = Bar(init_opts=opts.InitOpts())
- bar.add_xaxis(xaxis_data=x)
- bar.add_yaxis(series_name='A',y_axis=y1)
- bar.add_yaxis(series_name='B',y_axis=y2)
- bar.set_global_opts(title_opts=opts.TitleOpts(title='示例'))
-
- bro = QWebEngineView()
- html_path=os.getcwd()+'/'+'chart22.html'
- bar.render(html_path)
- bro.setUrl(QUrl(html_path.replace('\\','/')))
- self.scrollArea.setWidget(bro)
- print()
-
- if __name__ == "__main__":
- app = QtWidgets.QApplication(sys.argv)
- widget = Form()
- widget.show()
- sys.exit(app.exec_())
复制代码
救救孩子吧!!! |
|