'i want to display my api data in a bar chart in flutter

how can i display my api data in a bar chart ?

this is my api response

 {
  "jour1": 0,
  "jour2": 1,
  "jour3": 1,
  "jour4": 0,
  "jour5": 0,
  "jour6": 1,
  "jour7": 4
 }

this is how i fetch my api data, it works with pie chart and different response, but now i can't find how to use bar chart

pie chart fetch

  final response = await 
  http.get(Uri.parse("url"));
      final js = jsonDecode(response.body);
      final Map<String, double> d = {
        'absent' : js['all'].toDouble() - js['present'].toDouble(),
        'present' : js['present'].toDouble(),
      };
     return d;

This is the pieChart i used, it requires a map of data

 PieChart(
                            dataMap: ss.data,

                            chartRadius: MediaQuery.of(context).size.width / 1.7,
                            legendOptions: LegendOptions(
                                legendPosition: LegendPosition.bottom,
                                legendTextStyle: TextStyle(
                                  fontSize: 20,
                                )
                            ),
                            chartValuesOptions: ChartValuesOptions(
                                chartValueStyle: TextStyle(
                                    fontSize: 20,
                                    color: Colors.black
                                )
                            )
                        ),

that's why i tried the same in bar chart, but i can't find a barchart that uses map as its data.

 final response = await http.get(Uri.parse("url"));
final js = jsonDecode(response.body);
final Map<String, int> d = {
  'jour1' : js['jour1'],
  'jour2' : js['jour2'],
  'jour3' : js['jour3'],
  'jour4' : js['jour4'],
  'jour5' : js['jour5'],
  'jour6' : js['jour6'],
  'jour7' : js['jour7'],
};

return d;


Solution 1:[1]

I'm not entirely sure which package you are using for the PieChart, if any, but looking at https://google.github.io/charts/flutter/example/bar_charts/simple it seems you can use a map or custom object for this bar chart. I would highly recommend creating a custom object for your API data, but it might not be necessary with this package.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tray Denney