This is a migrated thread and some comments may be shown as answers.

Custom Palette for Pie Series

8 Answers 155 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jay
Top achievements
Rank 1
Jay asked on 06 Aug 2014, 05:09 AM
Hi,

can you guide me how i can make custom palette for pie and doughnut series

here is my code

public RadPieChartView doughnutChartView(List<DashBoardCharts> chart)
    {
        try
        {
            radPieChartView = new RadPieChartView(activity);
            doughnutSeries = pieseries.new DoughnutSeriesLegend(activity);

            legendView = new RadLegendView(activity);
            legendView.setLegendProvider(radPieChartView);

            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(100, 80);
            params.setMargins(10, 10, 10, 10);
            legendView.setLayoutParams(params);

            doughnutSeries.setValueBinding(new DataPointBinding()
            {
                @Override
                public Object getValue(Object o)
                {
                    return ((Dashboard.DashBoardCharts) o).getValue();
                }
            });
            String[] color={"#00FF00","#00FF23"};
            doughnutSeries.setData(chart);
            for(String col :color){
            collection.setFamily(doughnutSeries.paletteFamily());
            
                entry = new PaletteEntry(Color.parseColor(col));
            
            collection.add(entry);
            customPalette.seriesEntries().add(collection);
            doughnutSeries.setPalette(customPalette);
            
            }
            doughnutSeries.setShowLabels(true);
            radPieChartView.addView(legendView);
            radPieChartView.getSeries().add(doughnutSeries);
        } catch (Exception e)
        {
            e.printStackTrace();
        }
        return radPieChartView;
    }



regards,
jay

8 Answers, 1 is accepted

Sort by
0
Jay
Top achievements
Rank 1
answered on 08 Aug 2014, 06:44 AM
Here is what i have provide one color but i want to fill x number of colors as x number of category or values.
so please help ,me out to achieve dynamically add colors

public RadPieChartView pieChartView()
    {
         
        initData();
        PieseriesLegend pieSeriesLegend = new PieseriesLegend();            
        DoughnutSeriesLegend doughnutSeries = pieSeriesLegend.new DoughnutSeriesLegend(getBaseContext());
 
        RadPieChartView doughnutchartView = new RadPieChartView(this);
        RadLegendView legendView = new RadLegendView(this);
        legendView.setLegendProvider(doughnutchartView);

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(460,100);
        params.setMargins(10,10,10,10);
        legendView.setLayoutParams(params);

            doughnutSeries.setValueBinding(new DataPointBinding()
            {
                @Override
                public Object getValue(Object o)
                {
                    return ((MonthResults) o).getResult();
                }
            });
        doughnutSeries.setData(this.monthResults);
        ChartPalette customPalette = new ChartPalette();
      PaletteEntryCollection collection = new PaletteEntryCollection();
      collection.setFamily(doughnutSeries.paletteFamily());
      PaletteEntry entry = new PaletteEntry(Color.GREEN);
      collection.add(entry);
      customPalette.seriesEntries().add(collection);
      
      doughnutSeries.setPalette(customPalette);
      
        doughnutSeries.setShowLabels(true);
    doughnutchartView.addView(legendView);
        doughnutchartView.getSeries().add(doughnutSeries);
        return doughnutchartView;
    }

regards,
jay


0
Victor
Telerik team
answered on 11 Aug 2014, 07:32 AM
Hello Jay,

Thanks for writing.
May I suggest, that instead of creating a new palette, you simply get the chart palette and clone it. This way you will only need to tweak the existing palette entries. That is, if you don't actually want to overwrite everything.

Then as you add more data points, you simply add PaletteEntry objects and reapply your palette.

Regards,
Victor
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Jay
Top achievements
Rank 1
answered on 12 Aug 2014, 04:56 AM
hi,

thanks for the reply but can u give me some sample code for bar series where each bar has different color

regards,
jay
0
Jay
Top achievements
Rank 1
answered on 12 Aug 2014, 05:08 AM
here is what i have tried but its showing only one color


public RadCartesianChartView barChartView() {
        ChartPalette customPalette = new ChartPalette();
        PaletteEntryCollection collection = null;

        com.example.teleriksample.Color color = new com.example.teleriksample.Color();
        ArrayList<com.example.teleriksample.Color> arrayList = new ArrayList<com.example.teleriksample.Color>();

        color.setR(0);
        color.setG(0);
        color.setB(255);

        arrayList.add(color);
        color = new com.example.teleriksample.Color();
        color.setR(127);
        color.setG(255);
        color.setB(10);

        arrayList.add(color);
        color = new com.example.teleriksample.Color();

        color.setR(255);
        color.setG(122);
        color.setB(51);

        arrayList.add(color);

        PaletteEntry entry;
        try {
            initData();

            barchartView = new RadCartesianChartView(this);
            BarSeries barSeries = new BarSeries(this);

            barSeries.setCategoryBinding(new DataPointBinding() {
                @Override
                public Object getValue(Object o) {
                    return ((MonthResults) o).getMonth();
                }
            });
            barSeries.setValueBinding(new DataPointBinding() {
                @Override
                public Object getValue(Object o) {
                    return ((MonthResults) o).getResult();
                }
            });

            barSeries.setData(monthResults);

            for (int i = 0; i < arrayList.size(); i++) {
                entry = new PaletteEntry(Color.argb(255, arrayList.get(i)
                        .getR(), arrayList.get(i).getG(), arrayList.get(i)
                        .getB()));
                collection = new PaletteEntryCollection();
                collection.setFamily(barSeries.paletteFamily());
                collection.add(entry);
                customPalette.seriesEntries().add(collection);
            }

            barSeries.setPalette(customPalette);

            barchartView.getSeries().add(barSeries);

            CategoricalAxis horizontalAxis = new CategoricalAxis(this);
            barchartView.setHorizontalAxis(horizontalAxis);

            horizontalAxis.setLabelFitMode(AxisLabelFitMode.ROTATE);

            LinearAxis verticalAxis = new LinearAxis(this);
            barchartView.setVerticalAxis(verticalAxis);

            ChartPanAndZoomBehavior behavior = new ChartPanAndZoomBehavior();

            behavior.setZoomMode(ChartPanZoomMode.VERTICAL);
            behavior.setPanMode(ChartPanZoomMode.BOTH);
            barchartView.getBehaviors().add(behavior);
            barchartView.getBehaviors().add(new ChartSelectionBehavior());

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return barchartView;

    }
0
Jay
Top achievements
Rank 1
answered on 14 Aug 2014, 12:43 PM
hi,

for the first series doughnut i want to show label as well like its shows for "Appointments " with legends
please guide me how to do this, here i have attached the screen shot

regards,
jay

0
Victor
Telerik team
answered on 15 Aug 2014, 07:52 AM
Hi Jay,

Thanks for writing.
Before getting to your question I'd like to point out that your trial period has expired and you are no longer entitled to full support. Please consider purchasing the controls if you plan to use the controls and our support system.

If you purchase the controls you will have priority 24h support as well as access to the controls source code which will enable you to completely understand how it works and tweak it if necessary.

In order to have several bars with different colors you need to add several series to your chart and each series will have only one data point.

Regards,
Victor
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Jake
Top achievements
Rank 1
answered on 19 Aug 2014, 12:26 PM
Hi Victor,

can we give different color for each bar in same series?

Regards,
jake
0
Antony Jekov
Telerik team
answered on 22 Aug 2014, 12:07 PM
Hi Jake,

Having more than one color for a series is unnatural and it is not supported by our chart. It might be confusing for clients that are not used to it. If you however insist of using this approach I would recommend the approach that Victor has suggested - simply use more series. This will make it easier on you when describing them in the legend if you use one.

In theory you might be able to override the class that renders the bars, but I am not sure what the result might be, as I said, this is going outside of our designs.

You might consider purchasing a license as suggested by Victor. This will entitle you to our dedicated support where me and my team will be able to help you further with overriding and extending our controls and integrating them for your project needs.

Thank you for your time and all best!

Regards,
Antony Jekov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Chart
Asked by
Jay
Top achievements
Rank 1
Answers by
Jay
Top achievements
Rank 1
Victor
Telerik team
Jake
Top achievements
Rank 1
Antony Jekov
Telerik team
Share this question
or