Kltz
Kltz

Reputation: 1

How to set colors (Not Randomly) to pie chart's each slice in MPAndroidChart?

How to set colors (Not Randomly) to pie chart's each slice in MPAndroidChart?

Currently, I found this:

    PieDataSet dataSet = new PieDataSet(yVals1, "Election Results");
    dataSet.setSliceSpace(2f);
    dataSet.setSelectionShift(5f);

    // add a lot of colors

    ArrayList<Integer> colors = new ArrayList<Integer>();

    for (int c : ColorTemplate.VORDIPLOM_COLORS)
        colors.add(c);

    for (int c : ColorTemplate.JOYFUL_COLORS)
        colors.add(c);

    for (int c : ColorTemplate.COLORFUL_COLORS)
        colors.add(c);

    for (int c : ColorTemplate.LIBERTY_COLORS)
        colors.add(c);

    for (int c : ColorTemplate.PASTEL_COLORS)
        colors.add(c);

    colors.add(ColorTemplate.getHoloBlue());

    dataSet.setColors(colors);

Thanks

Upvotes: 0

Views: 1757

Answers (2)

Ngọc Lann
Ngọc Lann

Reputation: 11

You can choose whatever color you want to add to the list: For example, if you want 5 colors: red, blue, yellow, green, black:

dataSet.setColors(Color.RED, Color.BLUE, Color.yellow, Color.GREEN, Color.BLACK);

You can also add 2 rgb colors (red and brown) like that:

dataSet.setColors(Color.rgb(236, 42, 40), Color.rgb(132, 79, 45));

Upvotes: 1

Philipp Jahoda
Philipp Jahoda

Reputation: 51411

Actually the order of the colors simply goes along with the order you add your Entries.

Meaning: The first color you add will be the color used for the first Entry you added.

Also have a look at the documentation.

Upvotes: 0

Related Questions