Data:
const data={
"labels": [
0,
400,
800,
1200,
1600,
2000,
2400,
2800,
3200,
3600,
4000
],
"datasets": [
{
"axis": 'x',
"label": "FFF",
"borderColor": "Red",
"backgroundColor": "Red",
"data": [
{
"x": 2883,
"y": 129
},
{
"x": 3509,
"y": 118
},
{
"x": 3916,
"y": 73
}
]
}
]
};
I am providing both x & y axis values, the result should be like this for red line.
But for current config it rendering the line from start instead of specific point on x-axis.
2
Answers
You have to use
scatter chart
andshowline : true
option instead ofline chart
for this result.This is because you are using a line chart with default config.
By default a line chart uses a category scale and expects strings. In the dataset you specify an x, this x is the internal data format which for the catagory scale is not the value but the index.
The easyest approach would be to use a linear scale by setting
options.scales.x.type
to'linear'