How to make positive negative barchart

I wonder how i can make bar chart in flutter which shows positive in green when the number is positive and negative when the number is negative? I want to make it like this:


Can you also please show me the dummy data and show how the y-axis is red when it is for example -20 or when it is green for example 20. What i mean by this can you show red or green based on the data and show example of the data you are using?


1 Reply

YG Yuvaraj Gajaraj Syncfusion Team November 15, 2021 12:18 PM UTC

Hi FD, 
 
Greetings from Syncfusion. We have analyzed your query and we have created the sample with column chart having a positive and negative value, here we have assigned the red color to the negative values and green for the positive values and mapped this color to the respective segment by the poinColorMapper property of series. We have also attached the sample for your reference. 
 
Code snippet: 
void updateData() { 
    for (int i = 0; i < 10; i++) { 
      int randomYValue = _getRandomInt(-10, 10); 
      chartData.add(ChartSampleData( 
          i, 
          randomYValue, 
          randomYValue.isNegative 
              ? const Color.fromRGBO(199, 86, 86, 1) 
              : const Color.fromRGBO(107, 189, 98, 1))); 
    } 
  } 
 
 
Screenshot: 
  
  
We hope this will help you to fulfill your requirement. 
 
Regards, 
Yuvaraj. 


Loader.
Up arrow icon