I am trying to show multiple lines in highcharts.
So I was able to the multiple lines like the first chart. But it doesn’t make sense to me.
What is ideal is that all of the lines should be stretched to the x-axis like in the second chart.
X axis is a value of date as a number like 1660847299055
.
I have the following option for the first chart.
const option = {
xAxis: {
visible: false,
},
yAxis: {
reversed: true,
title: {
text: 'Deviation',
},
startOnTick: false,
endOnTick: false,
min: 0,
softMax: 15,
},
}
As the second chart said, I don’t care about the relations of x values between those three red, green, and blue lines. They should be stretched from start to end.
How can I implement this?
2
Answers
Using the
chart
handle you got after creating the chart you need to add a series for each linehttps://api.highcharts.com/class-reference/Highcharts.Chart.html#addSeries
Also
chart
has a member calledchart.series
for each line. You can play with this in the browser’s debugging tool console window to understand whats going on. You can iterate over that array to interact with the data and modify or add to it.Check out
xData
andyData
data has X and Y components. so adding data can be of the from value only[10,20,30,40]
or timeseries[[2020,10],[2021,20],[2022,30] ..]
x is year y is value.To change the data completely you need to find which line and use
setData
I would recommend reading this page from highcharts about series data and experimenting with it in the browsers Inspector window.
A possible solution based on the multiple x-axes idea (still don’t know if it fits the OP’s data format). The idea is to provide each series with its own x axis which will automatically adapt to the min and max of the data in that series. This works since none of the x axes are intended to be displayed.