Skip to content

add BorderRaduisMapper to ChartSeries #34

Closed

Description

@akdu12

I have a use case where i need to check the current value before creating the BorderRaduis and went through the documentation but i couldn't find a solution for it.
so maybe adding a borderRaduisMapper : (T point)=> BorderRaduis to the ChartSeries will make it easy to customize it.

Kind regards!

Activity

  1. SriramKiranSenthilkumar commented on Nov 2, 2020

    @SriramKiranSenthilkumar
    Contributor

    Hi @akdu12,

    Greetings from Syncfusion. We have analyzed your query at our end and the requested scenario can be achieved using a workaround with the help of the inheritance/extendability. We have created a simple workaround sample in which we have created a custom series renderer for the ColumnSeries by extending the ColumnSeriesRenderer so that we can override the createSegment method to customize the column series segments in the chart by creating a custom painter class which extends the ColumnSegment which holds the properties of each column series segment for customization. To set the border radius for each column segment based on the current values, you need to keep the chart data source globally and by checking the values of the chart data source you can customize the border-radius for the respective column segments. Please refer the code snippet below for further reference.

    // Initailize the chart's data source globally.
    List<_SalesData> chartData = <_SalesData>[
      _SalesData('Jan', 36),
      _SalesData('Feb', 28),
      _SalesData('Mar', 34),
      _SalesData('Apr', 32),
      _SalesData('May', 40)
    ];
    
    // State class that holds the chart widget
    class _MyHomePageState extends State<_MyHomePage> {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
            appBar: AppBar(
              title: const Text('Syncfusion Flutter chart'),
            ),
            body: SfCartesianChart(
                primaryXAxis: CategoryAxis(),
                // Your configurations
                series: <ChartSeries<_SalesData, String>>[
                  ColumnSeries<_SalesData, String>(
                      // Event with which the overring can be done in the chart.
                      onCreateRenderer: (ChartSeries<dynamic, dynamic> series) {
                        return CustomColumnSeriesRenderer();
                      },
                      dataSource: chartData,
                      xValueMapper: (_SalesData sales, _) => sales.year,
                      yValueMapper: (_SalesData sales, _) => sales.sales,
                      // Your configurations
                   )
                ]));
      }
    }
    
    // Custom colum series renderer for creating the custom segemnt painter
    class CustomColumnSeriesRenderer extends ColumnSeriesRenderer {
      CustomColumnSeriesRenderer();
    
      @override
      ChartSegment createSegment() {
        // Custom segement painter returned
        return CustomChartPainter();
      }
    }
    
    // Initialized Custom Segment painter for customizing each segements of the series based on the current segment index value.
    class CustomChartPainter extends ColumnSegment {
      // Initialized a rect to store the segment rect of each column
      Rect rect;
      @override
      void onPaint(Canvas canvas) {
        rect = segmentRect.outerRect;
        // Based on teh y value of the column, we have set the border radius for the each column segment
        // here, if the value is above 35, the bottom corner parts of the colum segement will be rounded.
        if (chartData[currentSegmentIndex].sales > 35) {
          segmentRect = RRect.fromRectAndCorners(rect,
              bottomLeft: Radius.circular(25), bottomRight: Radius.circular(25));
        // here, if the value is below 35, the top corner parts of the colum segement will be rounded.
        } else if (chartData[currentSegmentIndex].sales < 35) {
          segmentRect = RRect.fromRectAndCorners(rect,
              topLeft: Radius.circular(25), topRight: Radius.circular(25));
        } // You can set the radius values as per your wish using the necessary parameters(topLeft, topRight, bottomRight, bottomLeft) of the RRect.fromRectAndCorners method.
    
        // Called the superclass's methods and properties for column segment rendering.
        super.onPaint(canvas);
      }
    }
    

    Screenshot:
    Screenshot_20201102-184336

    We have also attached the workaround sample below for your reference.
    sample.zip

    Please check with above-attached sample and revert us if you would require further assistance on this.

    Also to mention that, if the provided workaround was not helpful in achieving your scenario then we kindly request you to share us with some example screenshots or reference link to understand your scenario/use case/requirement clearly so that it will be helpful in providing the solutions sooner.

    Regards,
    Sriram Kiran

  2. akdu12 commented on Nov 2, 2020

    @akdu12
    Author

    yes it works
    thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions