fl_chart
fl_chart copied to clipboard
Two axis Y with different variables
Example: https://echarts.apache.org/examples/en/editor.html?c=multiple-y-axis
I needed to implement linear chart with two Y variables. I used rightTitles and leftTitles. And calculated Spot Y for the second variable as (Y2 - minY2) / (maxY2 - minY2) * (maxY - minY) + minY to show it correctly in chart.
I needed to implement linear chart with two Y variables. I used rightTitles and leftTitles. And calculated Spot Y for the second variable as (Y2 - minY2) / (maxY2 - minY2) * (maxY - minY) + minY to show it correctly in chart.
Do you have an example to show me? I would be very grateful.
Looks like this
Thanks, @ldemyanenko your solution is smart.
@JErazo7 I think It should be handled outside of the chart
Looks like this
What should I do if the y-axis scale on the right is a different range and latitude?pls
We are also looking for the ability to do dual Y-axis.
(Came from #51)
Any update on this?
I am eagerly waiting for this feature... 👀
Any updates here? I need this feature. (Comming from #1199)
Nothing? Stopped here?
Is there any development on the issue? Still in need of this feature. Calculating the second spotY using the first one doesn't work for me since the ratio between my spotY values differs.
It's possible to insert a second variable that seems to refer to the right axis. The variable must be scaled to the left axis, and lineTouchData
of LineChartData
overrided to scale back the labels:
lineTouchData: LineTouchData(
touchTooltipData: LineTouchTooltipData(
getTooltipItems: (lineBarSpotList) {
final List<LineTooltipItem> lineTooltipItemList = lineBarSpotList.map((lineBarSpot) => LineTooltipItem(
(lineBarSpot.y * (lineBarSpot.bar.color == colorOfRightAxisVariable ? rightLeftRatio : 1)).toStringAsFixed(1),
TextStyle(color: lineBarSpot.bar.color, fontWeight: FontWeight.bold)
)).toList();
return lineTooltipItemList;
},
),
),
Since the order of the LineBarSpot's as parameters of the function depends on the order of the values (sometimes the value that must be scaled is the biggest and the first, some other is the smallest and the second), the correct LineBarSpot can be identified by the bar.color property.
Any updates on this would be much appreciated