如何使用MPAndroidChart创建多个堆积条形图?

时间:2016-03-14 11:22:59

标签: android mpandroidchart

这里是json,我想显示与MPAndroidChart library image一起显示的图表。

[
    {
        "MonthName": "February",
        "Year": "2016",
        "IssuesCount": 3,
        "ClientName": "A",
        "IssueStatus": "Total",

    },
    {
        "MonthName": "February",
        "Year": "2016",
        "IssuesCount": 13,
        "ClientName": "B",
        "IssueStatus": "Total",

    },
    {
        "MonthName": "February",
        "Year": "2016",
        "IssuesCount": 1,
        "ClientName": "A",
        "IssueStatus": "Closed",

    },
    {
        "MonthName": "February",
        "Year": "2016",
        "IssuesCount": 2,
        "ClientName": "B",
        "IssueStatus": "Closed",

    },
    {
        "MonthName": "February",
        "Year": "2016",
        "IssuesCount": 1,
        "ClientName": "A",
        "IssueStatus": "OutStanding",

    },
    {
        "MonthName": "February",
        "Year": "2016",
        "IssuesCount": 10,
        "ClientName": "B",
        "IssueStatus": "OutStanding",

    },
    {
        "MonthName": "March",
        "Year": "2016",
        "IssuesCount": 1,
        "ClientName": "A",
        "IssueStatus": "OutStanding",

    },
    {
        "MonthName": "March",
        "Year": "2016",
        "IssuesCount": 0,
        "ClientName": "B",
        "IssueStatus": "OutStanding",

    },
    {
        "MonthName": "March",
        "Year": "2016",
        "IssuesCount": 0,
        "ClientName": "A",
        "IssueStatus": "Closed",

    {
        "MonthName": "March",
        "Year": "2016",
        "IssuesCount": 0,
        "ClientName": "B",
        "IssueStatus": "Closed",

    },
    {
        "MonthName": "March",
        "Year": "2016",
        "IssuesCount": 3,
        "ClientName": "A",
        "IssueStatus": "Total",

    },
    {
        "MonthName": "March",
        "Year": "2016",
        "IssuesCount": 9,
        "ClientName": "B",
        "IssueStatus": "Total",

    }
]

我正在使用MPAndroidChart库,请建议如何继续这样做。我很难将特定月份的详细信息分组并显示单个月的多个条形图。

修改

enter image description here

1 个答案:

答案 0 :(得分:1)

这是可能的。

你需要什么:

  • 1 BarData个对象,填充:
  • 3个数据集(一个用于红色条,一个用于紫色,......)
  • 并且每个数据集都填充了堆叠的BarEntries
  • " bar-groups"之间的空间。可以通过barData.setGroupSpace(...)
  • 设置
  • 可以通过barDataSet.setBarSpace(...)
  • 设置各个条之间的空格

可以像这样创建堆叠的BarEntry

new BarEntry(new float[] { stackvalue1, stackvalue2 }, xIndex);

xIndex对应于条目应映射到的x轴上的月份(在您的情况下)。

This example创建的图表就像您在上图中显示的图表一样。