简体   繁体   English

图表。 是否可以制作这种类型的图表?

[英]Echarts. Is it possible to make this type of chart?

在此处输入图像描述

Is it possible to make this kind of chart?有可能制作这种图表吗?

Condition: when blue chart value is lower then black chart value area between them colored into green, otherwise in red.条件:当蓝色图表值低于黑色图表值区域时,它们之间的颜色为绿色,否则为红色。

I've played around areaStyle and visualMap but can not find a right solution.我玩过 areaStyle 和 visualMap 但找不到正确的解决方案。

Yes, it is possible.对的,这是可能的。 And it's not difficult to draw but a bit harder to support further.而且画起来不难,但更难支持。 I not sure if correctly understood what data model you'll use but I drafted exactly the same shape like in you picture.我不确定您是否正确理解了您将使用的数据 model 但我绘制的形状与您图片中的完全相同。

在此处输入图像描述

 var myChart = echarts.init(document.getElementById('main')); var axisData = [0,1,2,3,4,5,6,7]; var colors = { green: '#75e160', red: '#d8403e', blue: '#7447c8', black: '#000000' }; function upperDataGenerator(extremum) { var data = []; for (var i = 0; i <= extremum; i += 0.01) { data.push([i, -Math.sin(i)]) } return data } function lowerDataGenerator(extremum){ var data = []; for (var i = 0; i <= extremum; i += 0.01) { data.push([i, Math.sin(i)]) } return data } var maxChartValue = 3 * Math.PI var dataUpper = upperDataGenerator(maxChartValue); var dataLower = lowerDataGenerator(maxChartValue); option = { xAxis: { data: axisData, type: 'value', max: 'dataMax' }, yAxis: { data: axisData, type: 'value', min: -3, max: 3 }, series: [ { type: 'line', data: dataUpper, showSymbol: false, areaStyle: {}, lineStyle: { color: 'blue' } }, { type: 'line', data: dataLower, showSymbol: false, areaStyle: {}, lineStyle: { color: colors.black } } ], visualMap: [ { type: 'piecewise', show: false, seriesIndex: [0,1], orient: 'vertical', pieces: [ { min: 0, max: 0.5, color: colors.black }, ] }, { type: 'piecewise', show: false, seriesIndex: [1], dimension: 0, pieces: [ { min: 0, max: maxChartValue / 3, color: colors.green }, { min: maxChartValue / 3, max: maxChartValue - maxChartValue / 3, color: colors.red }, { min: maxChartValue / 2, max: maxChartValue, color: colors.green }, ], }, { type: 'piecewise', show: false, seriesIndex: [0], dimension: 0, pieces: [ { min: 0, max: maxChartValue / 3, color: colors.green }, { min: maxChartValue / 3, max: maxChartValue - maxChartValue / 3, color: colors.red }, { min: maxChartValue / 2, max: maxChartValue, color: colors.green }, ], }, ] }; myChart.setOption(option);
 <script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/4.7.0/echarts.min.js"></script> <div id="main" style="width: 800px;height:600px;"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM