MPAndroidChart icon indicating copy to clipboard operation
MPAndroidChart copied to clipboard

Specify color for each month?

Open noelbautista91 opened this issue 11 years ago • 5 comments

Is there any way to assign a certain color to a certain month? For ex:

if (mMonth == "Feb") { mMonthBar.setColor(Color.BLUE); }

I see that there is a way to theme or assign a template to a dataset, but I'm looking to customize in a way that each month or category has a consistent color.

noelbautista91 avatar Feb 18 '15 23:02 noelbautista91

This is something I would be happy to have as well.

louwetienne avatar Feb 19 '15 09:02 louwetienne

Good point. I am currently working on some kind of color-formatter interface that will allow the user to return a customized color based on theEntry at that position.

PhilJay avatar Feb 20 '15 21:02 PhilJay

Yes you can do it. Just create an array of color template and set it accordingly to your needs along with the data.

Bishalsingh avatar Feb 26 '15 04:02 Bishalsingh

Will it solve #383 ?

mathieudebrito avatar Feb 26 '15 15:02 mathieudebrito

@PhilJay First I thank you for great library. To set individual bar color I tried the below way. BarData barData = new BarData(getXAxisValues(postData), getBarDataSet(postData)); ....

private List getBarDataSet(SalesAndPipelineData postData) {

    //get the "value" field's value
    ArrayList<BarDataSet> barDataSets = null;
    barDataSets = new ArrayList<>();

    for (int i = 0; i < postData.getData().size(); i++) {

        ArrayList<BarEntry> barEntries = new ArrayList<>();
        BarEntry entry = new BarEntry((float) postData.getData().get(i).getValue(), i);
        barEntries.add(entry);

        BarDataSet barDataSet = new BarDataSet(barEntries, "");
        String possiblity = postData.getData().get(i).getPossiblity();
        if(possiblity.equals("High")){
            barDataSet.setColor(Color.parseColor("#00ff00"));
        }else if(possiblity.equals("Low")){
            barDataSet.setColor(Color.parseColor("#ff0000"));
        }else{
            barDataSet.setColor(Color.parseColor("#0000ff"));
        }

        barDataSet.setBarSpacePercent(10f);
        barDataSets.add(barDataSet);
    }
    return barDataSets;
}

I can set color to individual bar. But couldn't set the x-axis label and couldn't get the bar's value. If we can set color based on entry value, my app would be unique chart with MPAndroidChart. I am waiting.

vkarthikeyan avatar Jul 22 '15 14:07 vkarthikeyan