fl_chart icon indicating copy to clipboard operation
fl_chart copied to clipboard

Two axis Y with different variables

Open JErazo7 opened this issue 4 years ago • 14 comments

Example: https://echarts.apache.org/examples/en/editor.html?c=multiple-y-axis

JErazo7 avatar Sep 01 '20 03:09 JErazo7

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.

ldemyanenko avatar Sep 03 '20 15:09 ldemyanenko

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.

JErazo7 avatar Sep 03 '20 15:09 JErazo7

photo_2020-09-03_18-54-03 Looks like this

ldemyanenko avatar Sep 03 '20 15:09 ldemyanenko

Thanks, @ldemyanenko your solution is smart.

imaNNeo avatar Sep 05 '20 17:09 imaNNeo

@JErazo7 I think It should be handled outside of the chart

imaNNeo avatar Sep 05 '20 17:09 imaNNeo

photo_2020-09-03_18-54-03 Looks like this

What should I do if the y-axis scale on the right is a different range and latitude?pls

Mecil9 avatar Nov 09 '20 08:11 Mecil9

We are also looking for the ability to do dual Y-axis.

210aaa

(Came from #51)

imaNNeo avatar Mar 07 '21 20:03 imaNNeo

Any update on this?

eddiesTime avatar Jul 07 '21 08:07 eddiesTime

I am eagerly waiting for this feature... 👀

mk48 avatar Nov 18 '22 13:11 mk48

Any updates here? I need this feature. (Comming from #1199)

alexanderwwagner avatar Jan 15 '23 20:01 alexanderwwagner

Nothing? Stopped here?

DonnyDevIT avatar May 17 '23 14:05 DonnyDevIT

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.

FatihGeylan avatar Jan 23 '24 08:01 FatihGeylan

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.

image

ddodi1 avatar Jul 28 '24 14:07 ddodi1

Any updates on this would be much appreciated

Emtee100 avatar Aug 07 '24 09:08 Emtee100