Code Monkey home page Code Monkey logo

Comments (3)

SriramKiranSenthilkumar avatar SriramKiranSenthilkumar commented on September 27, 2024 1

Hi @archie-sh,

Greetings from Syncfusion. We have analyzed your scenario with the provided information and the requested scenario regarding hiding of only the left most or right most axis label in the chart can also be achieved with the help of the onAxisLabelRender and onActualRangeChanged callback events available in the SfCartesianChart. We have also created a simple sample and attached below in which we have used the above-mentioned events to hide the leftmost or rightmost axis label in the chart. Please refer the code snippet below for further reference.

   // First initialize two string variable to store the visible minimum and maximum axis values
  String axisMinimum;
  String axisMaximum;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text('Syncfusion Flutter chart'),
        ),
        body: SfCartesianChart(
            onActualRangeChanged: (args) {
              if (args.axisName == 'primayXAxis') {
                 // Storing the visible minimum and visible maximum values of the axis to use them for hiding the left and right most axis labels in the onAxisLabelRender event
                axisMinimum = args.visibleMin.toInt().toString();
                axisMaximum = args.visibleMax.toInt().toString();
              }
            },
            onAxisLabelRender: (args) {
              if (args.axisName == 'primayXAxis') {
                // To hide only the left most axis label by checking the axis minimum value and setting the empty string for the label text.
                if (args.text == axisMinimum) {
                  args.text = '';
                }
                // To hide only the right most axis label by checking the axis maximum value and setting the empty string for the label text.
                if (args.text == axisMaximum) {
                  args.text = '';
                }
              }
            },
            primaryXAxis: NumericAxis(
                edgeLabelPlacement: EdgeLabelPlacement.shift,
                name: 'primayXAxis'
            ),
            series: <ChartSeries<_SalesData, num>>[
              LineSeries<_SalesData, num>(
                dataSource: <_SalesData>[
                  _SalesData(2010, 35),
                  _SalesData(2011, 28),
                  _SalesData(2013, 34),
                  _SalesData(2014, 32),
                  _SalesData(2015, 40)
                ],
                xValueMapper: (_SalesData sales, _) => sales.year,
                yValueMapper: (_SalesData sales, _) => sales.sales,
                // your configurations
              )
            ]));
  }

screenshots:

  • Hiding the left most axis label in the chart.

Screenshot_20201029-175605

  • Hiding the right most axis label in the chart

Screenshot_20201029-175631

The sample for reference can be found below.
sample.zip

Please check with the above sample and revert us if you still have further concerns.

Regards,
Sriram Kiran

from flutter-widgets.

archie-sh avatar archie-sh commented on September 27, 2024

Hi, thank you for taking the time to respond and for providing the sample, thats going above and beyond. I can confirm the solution works. I am closing the ticket.

from flutter-widgets.

walsha2 avatar walsha2 commented on September 27, 2024

@SriramKiranSenthilkumar, I agree with @archie-sh. That was a fantastic response. Thank you for being so thorough. The community really appreciates it!

from flutter-widgets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.