Help setting custom colours in pie chart

I’m hoping someone can give me with the correct code to set a custom color for a segment of a pie chart using the servoy chart bean. It looks straight forward but everything I try is rejected. Although the sample CRM uses the pie chart it uses default colors and does not set them directly so no help there either :(

If I use…

elements.piechart.getColors(1)
``` to examine the standard colors used it seems to return a java Color object and I can use this to set another color, but again I have had no success with creating my own or indeed changing the RGB values that I can see in the Color object but cannot seem to access.

Has anybody done this? - help gratefully received as always!

Hi David,

Guessing :) but have you tried using the ```
elements.chart_pie.setColors(number, Color)


Cheers
Harry

Those beans are Java beans, and not “Servoy beans”. So it is most likely that they expect Java Color objects. Google for “Java awt color” and you will find resources that show you how to create a Java color.

Hi Harry - yeah, tried that - no luck!

Patrick - that’s more or less the conclusion I came to but I hadn’t had any luck in creating the java color object. I’ll look further and see if I can find the magic bit of code!

What script did you use do to create the color David?

Hi Marcel,

Nice to hear from you

Glad to report that the problem is solved - following Patrick’s suggestion I’ve cracked it :D

elements.pie_chart2.setColors(0,new java.awt.Color(0xC80021))
``` ... works very nicely!

Great!

And more examples:

elements.bean_366.setColors(2000, new java.awt.Color(0xff0000)); // '#ff0000'
elements.bean_366.setColors(3000, new java.awt.Color(0x0000ff)); // '#0000ff'
elements.bean_366.setColors(4000, new java.awt.Color(0xff00ff)); // '#ff00ff'
elements.bean_366.setColors(5000, new java.awt.Color(0x0f0f0f)); // '#0f0f0f'

Small tip: you could use Servoy’s helper to convert hex to a Java color object

var vMyColor = Packages.com.servoy.j2db.util.PersistHelper.createColor('#efefef')