其他分享
首页 > 其他分享> > echarts Dataset 对多数据动态图示化展示

echarts Dataset 对多数据动态图示化展示

作者:互联网

  echarts官网资源地址: https://echarts.apache.org/examples/zh/index.html

   
 @*前端图形创建*@
<div class="layui-card-body" style=" height: 360px; text-align: center;">
<div class="layui-col-md12 layui-col-xs12">
<div class="layui-card-body" id="chartdiv" style="height: 400px; background: #ffffff; "></div>
</div>
</div>

var mySBChart = echarts.init(document.getElementById('chartshebeidiv'), 'macarons');
官方案例: setTimeout(function () {
  option = {
    legend: {},
    tooltip: {
      trigger: 'axis',
      showContent: false
    },
    dataset: {
      source: [
        ['product', '2012', '2013', '2014', '2015', '2016', '2017'],
        ['Milk Tea', 56.5, 82.1, 88.7, 70.1, 53.4, 85.1],
        ['Matcha Latte', 51.1, 51.4, 55.1, 53.3, 73.8, 68.7],
        ['Cheese Cocoa', 40.1, 62.2, 69.5, 36.4, 45.2, 32.5],
        ['Walnut Brownie', 25.2, 37.1, 41.2, 18, 33.9, 49.1]
      ]
    },
    xAxis: { type: 'category' },
    yAxis: { gridIndex: 0 },
    grid: { top: '55%' },
    series: [
      {
        type: 'line',
        smooth: true,
        seriesLayoutBy: 'row',
        emphasis: { focus: 'series' }
      },
      {
        type: 'line',
        smooth: true,
        seriesLayoutBy: 'row',
        emphasis: { focus: 'series' }
      },
      {
        type: 'line',
        smooth: true,
        seriesLayoutBy: 'row',
        emphasis: { focus: 'series' }
      },
      {
        type: 'line',
        smooth: true,
        seriesLayoutBy: 'row',
        emphasis: { focus: 'series' }
      },
      {
        type: 'pie',
        id: 'pie',
        radius: '30%',
        center: ['50%', '25%'],
        emphasis: {
          focus: 'self'
        },
        label: {
          formatter: '{b}: {@2012} ({d}%)'
        },
        encode: {
          itemName: 'product',
          value: '2012',
          tooltip: '2012'
        }
      }
    ]
  };
  myChart.on('updateAxisPointer', function (event) {
    const xAxisInfo = event.axesInfo[0];
    if (xAxisInfo) {
      const dimension = xAxisInfo.value + 1;
      myChart.setOption({
        series: {
          id: 'pie',
          label: {
            formatter: '{b}: {@[' + dimension + ']} ({d}%)'
          },
          encode: {
            value: dimension,
            tooltip: dimension
          }
        }
      });
    }
  });
  myChart.setOption(option);
});

项目动态填充数据:

function setBZChart() {
var timestart = document.getElementById("timeyearBZ").value;
$.ajax({  //ajax动态取值
url: "/FSUManage/SumStatistics/JsonAuditIndex",
data: { CityId: 0, AreaId: 0, Month: timestart },
type: "post",
success: function (res) {
var returnres = $.parseJSON(res);
if (returnres.code == 0) {
setTimeout(function () {
option = {
legend: {},
tooltip: {
trigger: 'axis',
showContent: true
},
dataset: {
source: [ //后台动态拼接好json字符串直接赋值source
returnres.xaxis,
returnres.data,
returnres.data1,
returnres.data2
]
},
xAxis: { type: 'category' },
yAxis: { gridIndex: 0 },
grid: { top: '45%', containlable: true },
series: [
{ type: 'line', smooth: true, seriesLayoutBy: 'row', emphasis: { focus: 'series' } },
{ type: 'line', smooth: true, seriesLayoutBy: 'row', emphasis: { focus: 'series' } },
{ type: 'line', smooth: true, seriesLayoutBy: 'row', emphasis: { focus: 'series' } },

{
type: 'pie',
id: 'pie',
radius: '30%',
center: ['50%', '25%'],
emphasis: { focus: 'data' },
label: {
formatter: '{b}: ({d}%)'
},
encode: {
itemName: 'product',
value: '1月',
tooltip: '1月'
}
}
]
};
myChart.on('updateAxisPointer', function (event) {
var xAxisInfo = event.axesInfo[0];

if (xAxisInfo) {
var dimension = xAxisInfo.value + 1;
myChart.setOption({
series: {
id: 'pie',
label: {
formatter: '{b}: ({d}%)'
},
encode: {
value: dimension,
tooltip: dimension
}
}
});
}
});

myChart.setOption(option);
})
}
else {
layer.msg("获取失败", { icon: 5 });
}
}
});

}

</script>

 

官方案例图案示例:<官网详细案例地址:https://echarts.apache.org/examples/zh/editor.html?c=dataset-link>

项目案例图案示例:

个人笔记内容:

var LogJson = [@{
@Html.Raw(SmartNet.Core.JsonHelper.dtToJson(dtList).ToString().TrimEnd(']').TrimStart('['));
}];  

 @Html.Raw(isDealNameOne)



 

标签:图示,true,series,focus,Dataset,emphasis,type,echarts,row
来源: https://www.cnblogs.com/lwmwsh/p/14807176.html