简体   繁体   English

如何使用 Apache ECharts 在同一轴内安装不同长度的系列?

[英]How can I fit series with different lengths inside same axis with Apache ECharts?

I am using the Javascript ECharts library for displaying some data in my Angular 2+ app.我正在使用 Javascript ECharts库在我的 Angular 2+ 应用程序中显示一些数据。 I see that all the examples have some configuration like the following:我看到所有示例都具有如下配置:

{
  xAxis: [
    data: ['00:00', '01:15', '02:30', '03:45']
  ],
  series: [
   { name: 'A', type: 'line', data: [300, 280, 250, 260] },
   { name: 'B', type: 'line', data: [200, 120, 700, 290] },
  ]
}

But my data does not always provide values for all the labels in the x axis .但我的数据并不总是为 x 轴上的所有标签提供值 For example, I would need to fit these arrays of custom objects into the chart:例如,我需要将这些自定义对象的 arrays 放入图表中:

const series1 = [{ label: '00:00', value: 300 }, { label: '02:30', value: 120 }];
const series2 = [{ label: '03:45', value: 890} ];

Of course, I could manually insert null or empty values in all the series so that all of them provide a value for each label in the axis.当然,我可以手动插入 null 或所有系列中的空值,以便它们都为轴中的每个 label 提供一个值。 But I believe there should be a more straightforward way to achieve this in ECharts, as it is quite simple in other chart libraries like Kendo Charts.但我相信在 ECharts 中应该有更直接的方法来实现这一点,因为它在 Kendo Charts 等其他图表库中非常简单。

Assuming you are working with line chart, below is the solution, anyway it is not that different for other charts, just make sure your xAxis type is category Your xAxis type should be set to category, and data should be something like this假设您正在使用折线图,下面是解决方案,无论如何它与其他图表没有什么不同,只需确保您的 xAxis 类型是类别您的 xAxis 类型应该设置为类别,并且数据应该是这样的

  xAxis: [
    type: 'category'
    data: [ {name: '00:00'}, ....] 
  ]

your series data should look like this您的系列数据应如下所示

                   //dimx , value
const series2 = [['03:45',  890]];

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

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