imaNNeo / fl_chart

FL Chart is a highly customizable Flutter chart library that supports Line Chart, Bar Chart, Pie Chart, Scatter Chart, and Radar Chart.
https://flchart.dev
MIT License
6.77k stars 1.75k forks source link

I want to display the y-axis inside the chart #1458

Open chenCoB opened 11 months ago

chenCoB commented 11 months ago

I want to display the y-axis inside the chart, but I don’t see the corresponding configuration. Is this function available? Thanks for clearing up the confusion

image
imaNNeo commented 11 months ago

Unfortunately, it is not possible at the moment.

minhtaama commented 9 months ago

have you tried Transform.translate when building your TitleSide?

imaNNeo commented 9 months ago

have you tried Transform.translate when building your TitleSide?

You're right. As we use widgets to show titles, you can wrap it with Transform widget and it should work.

eliseyOzerov commented 6 months ago

The problem with this approach is that we still have to specify the reservedSize property, which takes up space on the side of the chart. If we want the chart to fill the whole parent AND have the titles inside, we can't do that as there's a forced margin in AxisChartScaffoldWidget. @imaNNeo Would it be possible to add a "useMargin" boolean or something similar to AxisChartData and then check for it in the stackWidgets function before adding the margin to the container?

In the meantime, we can use the extra lines api

extraLinesData: ExtraLinesData(
  horizontalLines: [10000, 7500, 5000, 2500, 0, -2500, -5000, -7500, -10000].map((y) {
    return HorizontalLine(
      y: y.toDouble(),
      strokeWidth: 0,
      color: Colors.white.withOpacity(0.1),
      label: HorizontalLineLabel(
        show: true,
        padding: EdgeInsets.only(left: 16.w, bottom: 2.w),
        labelResolver: (p0) {
          final value = (p0.y / 1000).abs();
          return value.toStringAsFixed(value == value.toInt() ? 0 : 1);
        },
        style: TextStyle(fontSize: 12.sp, fontWeight: FontWeight.w300),
      ),
    );
  }).toList(),
),
imaNNeo commented 5 months ago

Yes, we can do that. But the question is: should we do that? Because there might be another solution, something like showTitlesInside: false|true What do you think?

yuanhoujun commented 4 months ago

Any update?

eliseyOzerov commented 1 month ago

Sorry for the late reply Iman, forgot this was here 😅 The only thing I cared about at the moment was showing the titles inside the chart while filling the container, so as long as that happens, the API for that can be whatever, I think.