Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set maximum value on primary measure axis

This is a question for Flutter development using charts_flutter. Is there a parameter to fix the maximum value on the measure axis? I'm currently using desiredTickCount as a hack but I ideally only want 3 tickers (0,5,10) for a range of 0-10 on the measure axis.

Code snippet:
  Widget _createChart() {
        return new charts.BarChart(
          _createSampleData(),
          animate: true,
          vertical: false,


          primaryMeasureAxis: new charts.NumericAxisSpec(
            tickProviderSpec: new charts.BasicNumericTickProviderSpec(
              desiredTickCount: 11,
            ),
          ),
          barRendererDecorator: new charts.BarLabelDecorator(),
          // Hide domain axis.
          domainAxis:
              new charts.OrdinalAxisSpec(renderSpec: new charts.NoneRenderSpec()),
        );
      }

      static List<charts.Series<OrdinalSales, String>> _createSampleData() {
        final data = [
          new OrdinalSales('Liver', 8),
          new OrdinalSales('Heart', 4),
          new OrdinalSales('Spleen', 5),
          new OrdinalSales('Lung', 1),
          new OrdinalSales('Kidney', 2),
        ];

        return [
          new charts.Series<OrdinalSales, String>(
            id: 'Sales',
            domainFn: (OrdinalSales sales, _) => sales.year,
            measureFn: (OrdinalSales sales, _) => sales.sales,
            data: data,
            // Set a label accessor to control the text of the bar label.
            labelAccessorFn: (OrdinalSales sales, _) => '${sales.year}',
          ),
        ];
      }
    }

    class OrdinalSales {
      final String year;
      final int sales;

      OrdinalSales(this.year, this.sales);
    }
like image 203
Hayden Lak Avatar asked Aug 29 '18 10:08

Hayden Lak


People also ask

How do I change the axis range in Powerpoint?

Add or change the position of vertical axis label Click the chart, and then click the Chart Layout tab. Under Axes, click Axes > Vertical Axis, and then click the kind of axis label that you want.


1 Answers

If you really just want 0, 5 and 10 try using a StaticNumericTickProviderSpec

    primaryMeasureAxis: new charts.NumericAxisSpec(
      tickProviderSpec: new charts.StaticNumericTickProviderSpec(
        <charts.TickSpec<num>>[
          charts.TickSpec<num>(0),
          charts.TickSpec<num>(5),
          charts.TickSpec<num>(10),
        ],
      ),
    ),
like image 92
Richard Heap Avatar answered Sep 27 '22 23:09

Richard Heap