简体   繁体   English

Apache ECharts 未按时显示 markArea xAxis

[英]Apache ECharts not showing markArea on time xAxis

I'm using Apache ECharts 5.2.2 and try to show some markAreas in the chart on a time axis.我正在使用 Apache ECharts 5.2.2 并尝试在时间轴上的图表中显示一些标记区域。

Apache ECharts provide some useful examples to get into some specific options. Apache ECharts 提供了一些有用的示例来了解某些特定选项。 Area Pieces is an example where you can set up your own EChartsOption with markArea . Area Pieces是一个示例,您可以在其中使用markArea EChartsOption

I tried to adjust the example to my needs but I fail to get it running on time axis using Date object.我试图根据我的需要调整该示例,但我无法使用Date object 使其在时间轴上运行。

If you paste the following EChartsOption into the example, you get an idea.如果您将以下 EChartsOption 粘贴到示例中,您就会有所了解。

option = {
  xAxis: {
    type: 'time', // changed from 'category'
    boundaryGap: false
  },
  yAxis: {
    type: 'value',
    boundaryGap: [0, '30%']
  },
  visualMap: {
    type: 'piecewise',
    show: false,
    dimension: 0,
    seriesIndex: 0,
    pieces: [
      {
        min: new Date('2019-10-11'), // old tag was gt
        max: new Date('2019-10-13'), // old tag was lt
        color: 'rgba(0, 0, 180, 0.4)'
      },
      {
        min: new Date('2019-10-15'), // old tag was gt
        max: new Date('2019-10-17'), // old tag was lt
        color: 'rgba(0, 0, 180, 0.4)'
      }
    ]
  },
  series: [
    {
      type: 'line',
      smooth: 0.6,
      symbol: 'none',
      lineStyle: {
        color: '#5470C6',
        width: 5
      },
      markLine: {
        symbol: ['none', 'none'],
        label: { show: true },
        data: [{ xAxis: new Date('2019-10-11') }, { xAxis: new Date('2019-10-13') }, { xAxis: new Date('2019-10-15') }, { xAxis: new Date('2019-10-17') }]
      },
      areaStyle: {},
      data: [
        // changed from string
        [new Date('2019-10-10'), 200],
        [new Date('2019-10-11'), 560],
        [new Date('2019-10-12'), 750],
        [new Date('2019-10-13'), 580],
        [new Date('2019-10-14'), 250],
        [new Date('2019-10-15'), 300],
        [new Date('2019-10-16'), 450],
        [new Date('2019-10-17'), 300],
        [new Date('2019-10-18'), 100]
      ]
    }
  ]
};

visualMap defines pieces that has a begin tag min and an end tag max of the visualized area to highlight. visualMap定义具有要突出显示的可视化区域的开始标记min和结束标记maxpieces Unfortunately, the area does not accept the beginning and ending of the defined Date object and highlights the whole chart.不幸的是,该区域不接受定义的Date object 的开头和结尾,并突出显示整个图表。

What am I doing wrong to get it running on time axis?我做错了什么让它在时间轴上运行? I found a bug report that is fixed in version 5.2.1 for string time data.我发现了一个在 5.2.1 版中针对字符串时间数据修复的错误报告 Even string is not working so I guess, I do something wrong here... Any clue?甚至string都不起作用所以我想,我在这里做错了......有什么线索吗?

Thanks in advance!提前致谢!

I finally did it.我终于做到了。

The tags min and max in pieces needs a number to handle data in time axis correctly. pieces中的minmax标签需要一个数字才能正确处理时间轴上的数据。 So, giving the timestamp of Date object by calling method getTime() is enough.因此,通过调用getTime()方法给出Date object 的时间戳就足够了。

pieces: [
  {
    min: new Date('2019-10-11').getTime(),
    max: new Date('2019-10-13').getTime(),
    color: 'rgba(0, 0, 180, 0.4)'
  },
  {
    min: new Date('2019-10-15').getTime(),
    max: new Date('2019-10-17').getTime(),
    color: 'rgba(0, 0, 180, 0.4)'
  }
]

Maybe, someone else have the same problem.也许,其他人也有同样的问题。 The documentation of Apache ECharts is sometimes not accurate enough. Apache ECharts 的文档有时不够准确。

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

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