Flask 框架:运用Echarts绘制图形( 三 )


<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><link rel="stylesheet" href="https://cdn.lyshark.com/javascript/bootstrap/3.3.7/css/bootstrap.min.css"><script type="text/javascript" src="http://shimg.jingyanzongjie.com/230725/031T53O7-0.jpg"></script><script type="text/javascript" src="http://shimg.jingyanzongjie.com/230725/031T533F-1.jpg"></script></head><body><!--饼状图绘制方法--><div class="panel panel-primary" style="width: 40%;height: 30%;float: left"><div class="panel-heading"><h3 class="panel-title">饼状图绘制</h3></div><div class="panel-body"><div id="PieChart" style="width:100%; height: 300px"></div></div></div><!--柱状图绘制方法--><div class="panel panel-primary" style="width: 58%;height: 30%; float: right"><div class="panel-heading"><h3 class="panel-title">柱状图绘制</h3></div><div class="panel-body"><div id="HistogramChart" style="width:100%; height: 300px"></div></div></div><!--折线图绘制方法--><div class="panel panel-primary" style="width: 100%;height: 40%; float: left"><div class="panel-heading"><h3 class="panel-title">折线图绘制</h3></div><div class="panel-body"><div id="Linechart" style="width:100%; height: 460px"></div></div></div><!--饼状图绘制方法--><script type="text/javascript" charset="UTF-8">var kv = new Array();kv = {{ Address | safe }}var test = new Array();for(var logkey in kv){test.push( {value:kv[logkey], name:logkey} )}var display = function(){var echo = echarts.init(document.getElementById("PieChart"));var option = {legend: {orient: 'vertical',left: 'left',},series: [{type: 'pie',radius: '70%',center: ['50%', '50%'],detail: {formatter:'{value}'},data: test}]};echo.setOption(option,true);};display();</script><!--柱状图绘制方法--><script type="text/javascript" charset="UTF-8">var kv = new Array();var keys = new Array();var values = new Array();kv = {{ Types | safe }}for(var logkey in kv){keys.push(logkey);values.push(kv[logkey]);}var display = function() {var echo = echarts.init(document.getElementById("HistogramChart"));var option = {tooltip: {trigger: 'axis',axisPointer: {type: 'shadow'}},grid: {left: '3%',right: '4%',bottom: '3%',containLabel: true},xAxis: {type: 'category',data: keys},yAxis: {type: 'value'},series: [{data: values,type: 'bar'}]};echo.setOption(option,true);};display();</script><!--折线图绘制方法--><script type="text/javascript" charset="UTF-8">// 函数主要用于将传入的字典分解成key,value格式并返回var get_key_value = https://www.huyubaike.com/biancheng/function(kv){var keys = new Array();var values = new Array();for(var logkey in kv){keys.push(logkey);values.push(kv[logkey]);}return [keys,values];}// 输出1分钟负载var kv = new Array();kv = {{ x | safe }};var x = get_key_value(kv);// 输出5分钟负载var kv = new Array();kv = {{ y | safe }};var y = get_key_value(kv);// 输出15分钟负载var kv = new Array();kv = {{ z | safe }};var z = get_key_value(kv);// 显示利用率var display = function() {var echo = echarts.init(document.getElementById("Linechart"));var option = {title: {left: 'left',text: 'CPU 利用表',},// 调节大小grid: {left: '3%',right: '4%',bottom: '3%',containLabel: true},// tooltip 鼠标放上去之后会自动出现坐标tooltip: {trigger: 'axis',axisPointer: {type: 'cross',label: {backgroundColor: '#6a7985'}}},legend: {data: ['1分钟负载', '5分钟负载', '15分钟负载']},xAxis: {type: 'category',// data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']data: x[0]},yAxis: {type: 'value'},series:[{name: "1分钟负载",stack: "总量",//data: [10, 25, 99, 87, 54, 66, 2],data: x[1],type: 'line'},{name: "5分钟负载",stack: "总量",//data: [89, 57, 85, 44, 25, 4, 54],data: y[1],type: 'line'},{name: "15分钟负载",stack: "总量",//data: [1, 43, 2, 12, 5, 4, 7],data: z[1],type: 'line'}]};echo.setOption(option,true);};display();</script></body>

经验总结扩展阅读