admin管理员组文章数量:1297103
I'm plotting a graph with chartjs where the x-axis represents time and the y-axis the corresponding data.
Now i got data for today, last week, last month and last year.
var myLineChart = new Chart(ctx).Line(data, options);
var data = {
labels: ["last year", "last month", "last week", "today"],
datasets: [
{
label: "My First dataset",
data: [80, 81, 56, 40]
}
]
};
When i plot the graph, the distance between every point is the same. But this is not correct because the time intervals are not the same.
The distance between 'last year' and 'last month' should be bigger than the distance between 'last week' and 'last month'.
Anyone an idea how i can achieve a this with chartjs, when i look at the documentation i don't see any options for this.
I'm plotting a graph with chartjs where the x-axis represents time and the y-axis the corresponding data.
Now i got data for today, last week, last month and last year.
var myLineChart = new Chart(ctx).Line(data, options);
var data = {
labels: ["last year", "last month", "last week", "today"],
datasets: [
{
label: "My First dataset",
data: [80, 81, 56, 40]
}
]
};
When i plot the graph, the distance between every point is the same. But this is not correct because the time intervals are not the same.
The distance between 'last year' and 'last month' should be bigger than the distance between 'last week' and 'last month'.
Anyone an idea how i can achieve a this with chartjs, when i look at the documentation i don't see any options for this.
Share Improve this question asked May 13, 2015 at 13:22 mgoubertmgoubert 3231 gold badge5 silver badges17 bronze badges2 Answers
Reset to default 8You have to use an extension to chart.js that has data for both x and y values in the data structure. One that I found is Chart.Scatter.
The longer explanation is that by default, the labels you use in chart.js are just labels; they don't get parsed into any kind of x values.
You can use the Chart.js scatter chart type (https://www.chartjs/docs/latest/charts/scatter.html). Also remember to set showLine: true
in the datasets
options.
I found that this resulted in gaps at the start and end of the x axis. You can feed in the min and max ticks for x axis as follows:
scales: {
xAxes: [
{
display: false,
ticks: { max: maxX, min: minX }
}
],
yAxes: [
{
display: false
}
]
}
本文标签: javascriptChartjsplot data based with unequal time intervalsStack Overflow
版权声明:本文标题:javascript - Chartjs, plot data based with unequal time intervals - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741647662a2390284.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论