Jump to content
JChartFX Community
  • 0

How to style individual pie chart slices?


adam__moore

Question

Hi there!
 
We are using the pie chart to visualise attained skills and would really like to be able to change the colour of individual slices, so that, fo example, skills not yet achieved could be clear / grey
 
I can't seem to find a simple way of changing individual slice colour

Here's the code rendering one chart (it's generated from PHP via an SQL query)
 

<div class="il_ContainerListItem">Your score in Planning is 5 out of 7</div>
<div class="il_ContainerListItem"> (System model [4] / User [1])</div>
<div id="ChartDiv1"class="il_ContainerListItem" style="valign:bottom;width:120px;height:150px;display:inline-block"></div>
<script type="text/javascript" language="javascript">chart1 = new cfx.Chart();chart1.setGallery(cfx.Gallery.Pie);var data1 = [{"Label": "unset", "value":2}, {"Label": "model", "value":4}, {"Label": "user", "value":1}];chart1.setDataSource(data1);chart1.getLegendBox().setVisible(false);
chart1.create('ChartDiv1');</script>
 
Thanks in advance for any help!

Adam 
Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

If you know the index of the slice you want to configure, i.e. in your case if the slice is always the first slice (or you can loop through the data and recognize the slices you need to configure) you could do something like this

chart1.getPoints().getItem(-1,0).setColor("#A0A0A0");

The first parameter of -1 means for all series (you could also use 0 as your chart only has 1 series) and the second parameter of 0 is the index of the point (first point in your data set).

Regards,

JuanC 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...