简体   繁体   English

chart.js具有不同数据点的混合图表

[英]chart.js mixed chart with different data points

Trying to create a mixed chart of two bars & one line. 尝试创建两个条形和一条线的混合图表。
- The data received for the bars is an array of 3 values [each value represents a month] -条形图接收的数据是3个值的数组[每个值代表一个月]
- The data received for the line is an array of ~90 values [each value represents a day within these 3 months] -该行收到的数据是〜90个值的数组[每个值代表这3个月中的一天]

My problem is that I can't seem to figure out [assuming it's possible] how to overlap a month worth of values [the days] with one month's value... Instead, what I see is only the first 3 joints of the line. 我的问题是,我似乎无法弄清楚[假设有可能]如何将一个月的价值[天]与一个月的价值重叠...相反,我看到的只是该行的前三个关节。

Tried a lot of things, few examples [cause there aren't too many] but nothing worked for me. 尝试了很多事情,没有几个示例(因为没有太多示例),但是对我没有任何帮助。

data: {
  labels: ["April","May","June"],
  datasets: [{
     type: 'bar',
     data: [1000, 2000, 3000],
     label: "Bar One",
     backgroundColor: "blue",
     borderWidth: 1
  }, {
     type: 'bar',
     data: [500, 4000, 2500],
     label: "Bar Two",
     backgroundColor: "red",
     borderWidth: 1
  }, {
     type: 'line',
     data: [321, -350, , -361, 244, 231, .... , 548]
     label: "Line",
     borderColor: "green",
     fill: false
}]

This is a general example of the code I'm using. 这是我正在使用的代码的一般示例。 For the sake of this example I didn't include all of the xAxis/yAxis options I've tried because it doesn't seem to work for me at all & the only way I can, at least, to see the start of my line is if I clear those options. 就本例而言,我没有包含我尝试过的所有xAxis / yAxis选项,因为它似乎根本不适合我,至少我只能以这种方式来查看我的开始。线是,如果我清除这些选项。

The drawn blue line in the picture represents what I'm trying to accomplish. 图片中的蓝线代表了我要完成的工作。 The blue line at the bottom is what a actually get: 底部的蓝线是实际得到的:

图表

It works if length of data arrays are equals. 如果数据数组的长度相等,它将起作用。 You have 3 options: 您有3种选择:

  • Decrease line chart data array length to 3 (same as bar charts). 将折线图数据数组的长度减小到3(与条形图相同)。
  • Extend bar charts data length to length of line chart data array (fill empty items with null ), also for labels array. 将条形图数据长度扩展到折线图数据数组的长度(用null填充空白项),也适用于标签数组。
  • Define new x-axis for line chart. 为折线图定义新的x轴。

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

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