基于python利⽤pyecharts作图,实现图表随数据变化实时更新利⽤vue和echarts可以设置定时获取数据渲染页⾯,但pyecharts做的图在前端页⾯上为JS中的⼀个对象数据,(利⽤Python搭建服务器定时返回新作的图表太⿇烦⽬前不想这样做),那位⼤神有好办法不妨告知。。。
⽬前采⽤定时修改pyecharts图表对象的属性值,在渲染页⾯:
代码如下
<!-- 初始化echarts图表 -->
var chart_65e195a41f494479b5c980b285573936 = echarts.init(
// 创建图表各个参数
var option_65e195a41f494479b5c980b285573936 = {
"animation": true,
"animationThreshold": 2000,
"animationDuration": 1000,
"animationEasing": "cubicOut",
"animationDelay": 0,
"animationDurationUpdate": 300,
"animationEasingUpdate": "cubicOut",
"animationDelayUpdate": 0,
"color": [
"#c23531",
"#2f4554",
"#61a0a8",
"#d48265",
"#749f83",
"#ca8622",
"#bda29a",
"#6e7074",
"#546570",
"#c4ccd3",
"#f05b72",
"#ef5b9c",
"#f47920",
"#905a3d",
"#fab27b",
"#2a5caa",
"#444693",
"#726930",
"#b2d235",
"#6d8346",
"#ac6767",
"#1d953f",
"#6950a1",
"#918597"
],
"series": [
{
"type": "bar",
"name": "\u9500\u552e\u989d",
"legendHoverLink": true,
"data": [
84,
87,
45,
86,
64,
85,
118
],
"showBackground": false,
"barMinHeight": 0,
"barCategoryGap": "20%",
"barGap": "30%",
"large": false,
"largeThreshold": 400,
"seriesLayoutBy": "column",
"datasetIndex": 0,
"clip": true,
"zlevel": 0,
"z": 2,
"label": {
}
}
],
"legend": [
{
"data": [
"\u9500\u552e\u989d"
],
"selected": {
"\u9500\u552e\u989d": true },
"show": true,
"padding": 5,
"itemGap": 10,
"itemWidth": 25,
"itemHeight": 14
}
],
"tooltip": {
"show": true,
"trigger": "item",
"triggerOn": "mousemove|click", "axisPointer": {
"type": "line"
},
"showContent": true,
"alwaysShowContent": false,
"showDelay": 0,
"hideDelay": 100,
setoption"textStyle": {
"fontSize": 14
},
"borderWidth": 0,
"padding": 5
},
"xAxis": [
{
"show": true,
"scale": false,
"nameLocation": "end",
"nameGap": 15,
"gridIndex": 0,
"inverse": false,
"offset": 0,
"splitNumber": 5,
"minInterval": 0,
"splitLine": {
"show": false,
"lineStyle": {
"show": true,
"width": 1,
"opacity": 1,
"curveness": 0,
"type": "solid"
}
},
"data": [
"\u8349\u8393",
"\u8292\u679c",
"\u8461\u8404",
"\u96ea\u68a8",
"\u897f\u74dc",
"\u67e0\u6aac",
"\u8f66\u5398\u5b50"
]
}
],
"yAxis": [
{
"show": true,
"scale": false,
"nameLocation": "end",
"nameGap": 15,
"gridIndex": 0,
"inverse": false,
"offset": 0,
"splitNumber": 5,
"minInterval": 0,
"splitLine": {
"show": false,
"lineStyle": {
"curveness": 0,
"type": "solid"
}
}
}
],
"title": [
{
"text": "\u6d4b\u8bd5\u5b9e\u4f8b",
"subtext": "xxxxx",
"padding": 5,
"itemGap": 10
}
]};
// 为创建的echarst图表添加各设置
chart_65e195a41f494479b5c980b285573936.setOption(option_65e195a41f494479b5c980b285573936); # 定时修改charts对象的series属性中的data值,然后再为chart对象修改参数
var interval = setInterval(function () {
option_65e195a41f494479b5c980b285573936.series[0].data[6] -= 1;
console.log(1);
chart_65e195a41f494479b5c980b285573936.setOption(option_65e195a41f494479b5c980b285573936); },
1000
)
效果如下
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论