drawing line plot using [{x,y}] format #9685
-
As per my understanding of the docs, one of the formats I can use specify data is list of x,y pairs as shown in example below
However, I don't see any line plot being generated. If I change the plot type to 'scatter', I do see three points drawn correctly. Just wanted to know if this is one of the acceptable formats for line plot -- from the docs it seems it should be. Am I missing something? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
This is because by default the x axis is a category axis, this expects predefined labels. The reason a scatter plot works is because the type of the x axis gets changed to linear by default. If you do that it works fine: var config = {
type: 'line',
data: {
datasets: [{
data: [{
x: 10,
y: 20
}, {
x: 15,
y: 7
}, {
x: 20,
y: 10
}]
}]
},
options: {
scales: {
x: {
type: 'linear'
}
},
parsing: false
}
}; |
Beta Was this translation helpful? Give feedback.
-
Got it. Thank you. |
Beta Was this translation helpful? Give feedback.
This is because by default the x axis is a category axis, this expects predefined labels. The reason a scatter plot works is because the type of the x axis gets changed to linear by default. If you do that it works fine: