猫史档案馆


[python作品]图表分析

用户:皮皮黑客皮皮黑客查看:0 回复:0 评论:0 创建时间:2022-01-23T12:24:15


主程序:importosimportsysfromPySide2.QtWidgetsimport*fromui_chartsimportUi_ChartsfromplotsimportplotsfromPySide2.QtCoreimportQUrlfromPySide2.QtWebEngineWidgetsimportQWebEngineView classMyCharts(QMainWindow,Ui_Charts):def__init__(self):super().__init__()self.setupUi(self)self.init_set()self.show() self.pbtn_data.clicked.connect(self.select_file)self.cb_chart_list.currentIndexChanged.connect(self.plot) definit_set(self):self.browser=QWebEngineView()self.vl_chart.addWidget(self.browser) defselect_file(self):self.data_file,_=QFileDialog.getOpenFileName(caption='选择数据文件',filter='(*.json)')self.lb_info.setText(self.data_file)self.plot() defplot(self):index_text=self.cb_chart_list.currentText()ifself.data_file:plots(self.data_file,index_text)self.browser.load(QUrl.fromLocalFile(os.path.realpath('render.html'))) if__name__=='__main__':app=QApplication(sys.argv)window=MyCharts()sys.exit(app.exec_())  副程序(先用这个,(可以改参数)):importosimportwebbrowserimportjson frompyechartsimportBar,Line,Pie defplots(data_fil,type):withopen(data_fil)asf:data=json.load(f) atttr=data['attr']value=data['velue']iftype=='柱状图':chart=Bar('柱状图')eliftype=='折线图':chart=Line('折线图')eliftype=='饼状图':chart=Pie('饼状图') chart.add(type,attr,value)chart.render()webbrowser.open("file://"+os.path.realpath("render.html")) if__name__=='__main__':plots('饼状图')#设置哪种图PS:此程序在饼状图状态下可以查看百分数  imgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E6%90%93%E5%A4%B4.gif"alt="emotion_编程猫_搓头"


回复

上一页1 页 / 共 0下一页