Custom Palette for Pie Series

9 posts, 0 answers
  1. Jay
    Jay avatar
    18 posts
    Member since:
    May 2014

    Posted 06 Aug 2014 Link to this post

    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
  2. Jay
    Jay avatar
    18 posts
    Member since:
    May 2014

    Posted 08 Aug 2014 in reply to Jay Link to this post

    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


  3. DevCraft banner
  4. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 11 Aug 2014 Link to this post

    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.

     
  5. Jay
    Jay avatar
    18 posts
    Member since:
    May 2014

    Posted 11 Aug 2014 in reply to Victor Link to this post

    hi,

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

    regards,
    jay
  6. Jay
    Jay avatar
    18 posts
    Member since:
    May 2014

    Posted 12 Aug 2014 in reply to Jay Link to this post

    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;

        }
  7. Jay
    Jay avatar
    18 posts
    Member since:
    May 2014

    Posted 14 Aug 2014 in reply to Jay Link to this post

    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

  8. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 15 Aug 2014 Link to this post

    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.

     
  9. Jake
    Jake avatar
    8 posts
    Member since:
    Aug 2014

    Posted 19 Aug 2014 in reply to Victor Link to this post

    Hi Victor,

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

    Regards,
    jake
  10. Antony Jekov
    Admin
    Antony Jekov avatar
    88 posts

    Posted 22 Aug 2014 Link to this post

    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.

     
Back to Top
DevCraft banner