Pie Chart Border Color

1,165 views
Skip to first unread message

Buczek

unread,
Jul 5, 2013, 1:50:24 AM7/5/13
to andro...@googlegroups.com
I am creating a pie chart and am looking to change the black border color. I successfully changed the background color using:

pie.getBackgroundPaint().setColor(Color.gray);

I have tried the following with no luck:
pie.getBorderPaint().setColor(getResources().getColor(R.color.blue));
pie.getBorderPaint().clearShadowLayer();
pie.setBorderStyle(Plot.BorderStyle.NONE, null, null);

On previous graphs that I have created I would have used
getGraphWidget
and from there manipulated the background how I needed, however PieChart does not include this. I am wondering if there is another option I can use while I wait for PieChart to have a full release.

Thanks in advance
borderColor.png

Nick

unread,
Jul 5, 2013, 10:10:30 AM7/5/13
to andro...@googlegroups.com
Hi Buczek,

In the case of Pie charts, the border is considered part of the individual series format; that way you can increase/decrease thickness etc. to get a highlighting effect on the segment(s) of interest.  In your particular case I believe the Paint instance you want is SegmentFormatter.getOuterEdgePaint().

Nick

Buczek

unread,
Jul 5, 2013, 10:51:43 AM7/5/13
to andro...@googlegroups.com
Thanks for the quick response Nick. I should have been more clear. The black line around the pie graph itself is just fine. I was referring to the black line around the whole view that the pie chart is in, which can only be easily seen when you change the getBackgroundPaint().setColor().

Thanks again for your help.

Nick

unread,
Jul 5, 2013, 12:08:30 PM7/5/13
to
Ahhh - I believe that's actually the plot's borderPaint.  Try this:

plot.getBorderPaint().setColor(Color.TRANSPARENT);

UPDATE:  I just noticed that in your original post you mentioned already trying something similar.  This really should work though; all the border drawing logic is in the base class Plot which is common to both Pie and XY plots, neither of which override the default behavior.  Are you sure you arent making the change after the plot has been drawn?  You can try calling plot.redraw() immediately after changing the border to be sure.

Nick

Nick

unread,
Jul 5, 2013, 12:26:02 PM7/5/13
to
So Im an Idiot.  Your initial instincts were correct.  What needs to happen is that PieChart needs to provide a getter/setter for it's PieWidget instance.  In the meantime, I think something like this will work:

for(int i = 0; i < plot.getLayoutManager().size(); i++) {
  Widget w = plot.getLayoutManager().get(i);
  if(w instanceof PieWidget) {
    ((PieWidget) w).getBorderPaint().setColor(Color.BLUE);
    break;
  }
}

You will still probably need to disable the Plot's outer border paint as well though.

Buczek

unread,
Jul 5, 2013, 9:47:29 PM7/5/13
to andro...@googlegroups.com
I think we might be getting closer to the correct solution. I tried the getBorderPaint() and then redraw() as you suggested, but this still didn't work. I also tried the for loop you suggested which retrieved the PieWidget, but getBorderPaint() and getBackgroundPaint() both return null. I also checked and the LayoutManager is only finding one PieWidget. Any idea why the getBackgroundPaint and getBorderPaint() methods are returning null?

Thanks again for all of your help Nick. 

Nick

unread,
Jul 5, 2013, 10:06:14 PM7/5/13
to andro...@googlegroups.com
As a last resort I broke out the DemoApp and tried to modify it to remove all borders.  Heres what I did:

-Added android:background="#FFFFFF" to outermost LinearLayout
-Added the following two lines to SimplePieChartActivity.java:

pie.getBorderPaint().setColor(Color.TRANSPARENT);
pie
.getBackgroundPaint().setColor(Color.TRANSPARENT);


With just these changes no borders were visible whatsoever.  In other words it appears to be totally unnecessary to access the PieWidget get remove anyborder(s).  It seems like this border must be coming from somewhere outside Androidplot.  Is it possible a border is defined on an enclosing View?


Buczek

unread,
Jul 8, 2013, 6:00:22 PM7/8/13
to andro...@googlegroups.com
Thank you so much Nick! The change to outermost LinearLayout did the trick. No idea why that would have made such a big difference. Either way, thank you! I was beginning to think I was going crazy trying to solve it.

Raine

unread,
Oct 21, 2013, 4:33:33 AM10/21/13
to andro...@googlegroups.com, mary...@sxchange.com.ph
Hi Nick. None of the solutions above worked for me. I'm trying to implement a piechart on my fragment. These are the codes:

...

pie.addSeries(new Segment("s1", 10), sf1);

pie.addSeries(new Segment("s1", 1), sf2);

pie.addSeries(new Segment("s1", 10), sf3);

pie.addSeries(new Segment("s1", 10), sf4);

        

pie.getRenderer(PieRenderer.class).setDonutSize(0/100f, PieRenderer.DonutMode.PERCENT);

pie.getBorderPaint().setColor(Color.TRANSPARENT);

pie.getBackgroundPaint().setColor(Color.WHITE);

                

pie.redraw();

...


XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    style="@style/sample_activity"

    android:background="@drawable/loginback"

    android:orientation="vertical" >


    <com.androidplot.pie.PieChart

        android:id="@+id/mySimplePieChart"

        android:layout_width="250dp"

        android:layout_height="250dp"

        android:layout_weight="1" />


Attached is the output. Thanks!

Screen Shot 2013-10-21 at 4.27.41 PM.png
Reply all
Reply to author
Forward
0 new messages