日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

echarts统计x轴区间的数值

發(fā)布時間:2025/3/21 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 echarts统计x轴区间的数值 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

有時我們需要統(tǒng)計自定義echarts圖,統(tǒng)計x軸區(qū)間的y軸數(shù)量。

思路是利用echarts的自定義配置:option.series[i].type='custom'中的renderItem(params, api)函數(shù)進(jìn)行處理,這里包括了兩個參數(shù):params是對應(yīng)每一個dataItem的數(shù)據(jù)信息;api是可調(diào)用的方法(api.value()和api.coord())。詳情可以查看官方文檔。

以下是改自官方實例:?https://www.echartsjs.com/examples/editor.html?c=bar-histogram?,把以下引用 ecStat.js來處理數(shù)據(jù)的部分修改成自己拼裝成需要的格式

var bins = ecStat.histogram(girth); var 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]]; });

原因是引用ecStat.js處理數(shù)據(jù)時,有時出現(xiàn)以下錯誤,暫時沒找到解決方法。

改寫后的代碼顯示效果如下:

?

<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];
//自定義拼裝數(shù)據(jù)方式
     var edata = new Array();var scopeMin = 0;var scopeMax = 100;var interval = (scopeMax-scopeMin)/10;var tmin = scopeMin;while(tmin < scopeMax){var x0 = tmin; var x1 = tmin+interval;var 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],y: 2,tooltip: 2,label: 2},// data: data data: 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>

?

轉(zhuǎn)載于:https://www.cnblogs.com/HexUha/p/11141651.html

總結(jié)

以上是生活随笔為你收集整理的echarts统计x轴区间的数值的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。