Numerical statistics x-axis interval echarts

Sometimes we need to count the number of y-axis echarts custom map, statistics x-axis range.

Echarts idea is to use a custom configuration: option.series [i] .type = 'custom' in renderItem (params, api) processing function, here including two parameters: params data corresponding to each dataItem; api is callable methods (api.value () and api.coord ()). For more information please see the official documents.

The following example is adapted from the official:  https://www.echartsjs.com/examples/editor.html?c=bar-histogram  part, the following reference ecStat.js processes data into a format modifying their assembled into the desired

var bins = ecStat.histogram(girth);
where min = infinity;
var max = -Infinity;

edata = echarts.util.map(bins.data, function (item, index) {
   var x0 = bins.bins[index].x0;
   var x1 = bins.bins[index].x1;
   interval = x1 - x0;
   min = Math.min(min, x0);  
  max = Math.max(max, x1);   return [x0, x1, item[1]]; });

The reason is that when referencing ecStat.js processing data, the following error may occur, temporarily did not find a solution.

Code rewriting display as follows:

 

<div id="main1" style="width: 1000px;height: 500px"></div>
<script type="text/javascript">
    $(function(){
        generateChart();
    });
    function generateChart(){
        var myChart1 = echarts.init(document.getElementById('main1'));
        var girth =  [19, 26.4, 34, 41.4, 42.4, 42.7, 42.9, 43.1, 43.2, 43.3, 43.3, 43.3, 44.9, 45.4, 46.2, 46.7, 48, 48, 49.1, 54.2];
        //自定义拼装数据方式
     was edata = new Array (); was scopeMin = 0 ; was scopeMax = 100 ; was Interval = (scopeMax - scopeMin) / 10; where tmin = scopeMin; while (t min < scopeMax) { where x0 = t min; where x1 = t min + interval; was samplenum= 0; for(var i=0;i<girth.length;i++){ if((scopeMin == x0 && girth[i] < x0) || (x0 <= girth[i] && x1 > girth[i]) ||(scopeMin == x1 && girth[i] > x1)) { samplenum++; } } tmin += interval; edata.push([x0, x1, samplenum]); } var option = { color: ['rgb(25, 183, 207)'], grid: { top: 80, containLabel: true }, xAxis: [{ type: 'value', min: scopeMin, max: scopeMax, interval: interval }], yAxis: [{ type: 'value', }], series: [{ name: 'height', type: 'custom', renderItem: renderItem, label: { normal: { show: true, position: 'top' } }, encode: { x: [0, 1], and: 2 , tooltip: 2, label: 2 }, // date: date: edata }] }; myChart1.setOption(option); window.onresize = function () { myChart1.resize(); } } function renderItem(params, api) { var yValue = api.value(2); var start = api.coord([api.value(0), yValue]); var size = api.size([api.value(1) - api.value(0), yValue]); var style = api.style(); return { type: 'rect', shape: { x: start[0] + 1, y: start[1], width: size[0] - 2, height: size[1] }, style: style }; } </script>

 

Guess you like

Origin www.cnblogs.com/HexUha/p/11141651.html
Recommended