简体   繁体   English

ECharts Apache:条形图 - 添加水平线

[英]ECharts Apache: Bar chart - add horizontal level line

I use EChart.JS in my project.我在我的项目中使用 EChart.JS。

Here is my Bar chart:这是我的条形图: 在此处输入图片说明

I need to add an accent as a horizontal level line for each bar.我需要为每个条添加一个重音作为水平线。 And also to add a default value (red dashed line).并且还要添加一个默认值(红色虚线)。

So it should look something like this:所以它应该看起来像这样:

在此处输入图片说明

var myChart = echarts.init(document.getElementById("sleep_graph"), null, { renderer: 'svg' });

   var option;

   option = {
       xAxis: {
           type: 'category',
           data: [1, 2, 3, 4],
           show: false
       },
       yAxis: {
           type: 'value',
           splitLine: {
               show: false
           }
       },
       series: [
           {
               data: [
                   {
                       value: @sleepGraph.DeepSleepDurationValue,
                        itemStyle: {
                           color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                               { offset: 0.2, color: '@sleepGraph.DeepSleepDurationGraphColor' },
                               { offset: 1, color: 'white' }
                           ]),
                           opacity: 0.8
                       },
                       label: {
                           show: true,
                           position: 'top',
                           color: '@sleepGraph.DeepSleepDurationGraphColor',
                           fontWeight: 'bold'
                       },
                       labelLine: {
                           show: true,
                           lineStyle: {
                               type: 'solid',
                               color: 'black',
                               width: 55,
                           }
                       }
                   },
                   {
                       value: @sleepGraph.SleepDurationValue,
                       itemStyle: {
                           color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                               { offset: 0.2, color: '@sleepGraph.SleepDurationGraphColor' },
                               { offset: 1, color: 'white' }
                           ]),
                           opacity: 0.8
                       },
                       label: {
                           show: true,
                           position: 'top',
                           color: '@sleepGraph.SleepDurationGraphColor',
                           fontWeight: 'bold'
                       }
                   },
                   {
                       value: @sleepGraph.LightSleepDurationValue,
                       itemStyle: {
                           color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                               { offset: 0.2, color: '@sleepGraph.LightSleepDurationGraphColor' },
                               { offset: 1, color: 'white' }
                           ]),
                           opacity: 0.8
                       },
                       label: {
                           show: true,
                           position: 'top',
                           color: '@sleepGraph.LightSleepDurationGraphColor',
                           fontWeight: 'bold'
                       }
                   },
                   {
                      value: @sleepGraph.RemSleepDurationValue,
                      itemStyle: {
                           color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                               { offset: 0.2, color: '@sleepGraph.RemSleepDurationGraphColor' },
                               { offset: 1, color: 'white' }
                           ]),
                           opacity: 0.8
                       },
                       label: {
                           show: true,
                           position: 'top',
                           color: '@sleepGraph.RemSleepDurationGraphColor',
                           fontWeight: 'bold'
                       }
                   }

               ],
               type: 'bar',
               barWidth: 35,
               showBackground: true,
               backgroundStyle: {
                   color: 'rgba(180, 180, 180, 0.2)'
               }
           }
       ]
   };

   option && myChart.setOption(option);

According to ESChart , there's only chart line has markline property (But it only provide single markline).根据ESChart ,只有 图表线具有标记线属性(但它只提供单个标记线)。 So there's no way to add horizontal level line to bar chart in ESChart.js所以没有办法在 ESChart.js 中向条形图添加水平线

But you can try highcharts , it provides adding marker at the chart .但是你可以试试highcharts ,它提供了在图表上添加标记的功能

      marker: {
        symbol: 'c-rect',
        lineColor: 'red',
        lineWidth:3,
        radius: 10
      },
      type: 'scatter',

I failed to see your image but from your description, I think it's possible to do so with an extra bar series stacking on it.我没能看到您的图片,但根据您的描述,我认为可以通过在其上堆叠额外的条形系列来实现。 See examples at: https://www.makeapie.com/editor.html?c=xwigwFaytn and https://www.makeapie.com/editor.html?c=xD58D_iJlS .请参阅以下示例: https : //www.makeapie.com/editor.html?c=xwigwFaytnhttps://www.makeapie.com/editor.html?c=xD58D_iJlS

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

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