PhilJay / MPAndroidChart

A powerful 🚀 Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, panning and animations.
Other
37.56k stars 9.01k forks source link

Grouping datasets in MPAndroid charts #3401

Open elnazem opened 7 years ago

elnazem commented 7 years ago

Hi i have 2 dataset and i want to make a chart with mpandroidchart, this is my data set in json format :

const bar_chart_point_ver=
{
"datasets":[
  { 
   "name" :"set1",
   "setColor":["#004D40","#004D40","#004D40","#004D40","#e74c3c","#f1c40f","#3498db"],
   "points": [
    {
      "x": "eli",
      "y": "24"}
    ,{
      "x": "mah",
      "y": "38"}
      ,{
     "x": "sa",
      "y": "77"
    }
    ,{
     "x": "ni",
      "y": "17"
    }

  ]
},
{   
   "name" :"set2",
      "setColor":["#3498db"],
   "points": [
    {
      "x": "eli",
      "y": "12"}
    ,{
      "x": "mah",
      "y": "24"}
      ,{
     "x": "sa",
      "y": "125"
    }
    ,{
     "x": "ni",
      "y": "7"
    }

  ]
}]
};

and i want to have a grouped chart , for example in my data sets i have "eli" with value 12 and 24 and i want these values beside each other but it shows me like this :

enter image description here

and this is my java code :

  //float groupSpace = 0.06f;
        float groupSpace = 0.01f;
        float barSpace = 0.02f; // x2 dataset
        //float barWidth = 0.45f; // x2 dataset
        float barWidth = 0.1f; // x2 dataset
        data.setBarWidth(barWidth); // set the width of each bar
       // mChart.setData(data);
        mChart.groupBars(0f, groupSpace, barSpace); // perform the "explicit" 
        grouping
        mChart.invalidate(); // refresh
       // mChart.getBarData().setBarWidth(barWidth);
        //mChart.getXAxis().setAxisMinValue(startYear);
        mChart.getXAxis().setAxisMaximum(i-1);
        //mChart.groupBars(0, groupSpace, barSpace);
        mChart.setFitBars(true);

        mChart.invalidate();
       // mChart.groupBars(0, groupSpace, barSpace);
moshlp commented 7 years ago

if the graphic is OK but the lines are not in the order you want, why don´t rearrange the data list, and create a single barchart with only one list? no grouped

juesai2015 commented 6 years ago

hi @elnazem , Is this problem solved? I met too