Is it possible to add a secondary vertical axis within a line chart?
lineChartOptions: any = {
scales: {
yAxes: [
{
id: 'yAxis1',
position: 'left'
},
{
id: 'yAxis2',
position: 'right'
}
]
}
};
lineChartData.push({
data: [1, 2 , 3],
label: "Data 1",
yAxisID: 'yAxis1'
});
lineChartData.push({
data: [1, 2 , 3],
label: "Data 2",
yAxisID: 'yAxis2'
});
Seems it solved. If it is not solved, considering to reopen.
It seems this must be set the first time lineChartData is declared. For example, if I declare lineChartData:
private lineChartData: any[] = [ {}, {} ];
and then later replace it with:
this.lineChartData = [
{ data: [1, 2, 3], label: "Data 1", yAxisID: "yAxis1" },
{ data: [1, 2, 3], label: "Data 2", yAxisID: "yAxis2" }
];
then the axis preference won't be honored.
But you can start by declaring your axes:
private lineChartData: any[] = [ { yAxisID: 'yAxis1' }, { yAxisId: 'yAxis2' } ];
does not work with v 2.6.0 , I get :
"Cannot read property 'getBasePixel' of undefined"
"Cannot read property 'skip' of undefined"
finaly made it work but these have to be in options, not data
scales: {
yAxes: [
{
id: 'yAxis1',
ticks: {
steps : 10,
stepValue : 10,
//max : 100,
beginAtZero:true,
position:'left'
}
},
{
id: 'yAxis2',
ticks: {
steps : 10,
stepValue : 10,
//max : 100,
beginAtZero:true,
position:'right'
}
}
]
}
I come up with the same problem,How can I solve this.......? @phil123456
How to add vertical line to the line chart?
I have set min and max for each vertical axis. But I still find the values of first y axis column are considered to plot. How to plot each line based on its scaling values?
How to a vertical y-axis dynamically through typescript function?
Most helpful comment