Note that there are some explanatory texts on larger screens.

plurals
  1. POHighcharts - increment a class name so piechart slices can be uniquely styled in style.css
    primarykey
    data
    text
    <p>I am creating a HighCharts pie chart and want finer styling control over each slice -- I want light slices to have dark dataLabels and vice versa.</p> <p>So, I want to be able to style the slices using my style.css file. I've inserted a class name (slice) in the dataLabels setup, plus a custom function to cycle through all my slices and give them unique classes:</p> <pre><code>function colorSlices(chart) { var count = 1; $(".slice").each(function(){ $(this).addClass("slice-"+count); count++; }); }; var chart; $(document).ready(function() { // Build the chart chart = new Highcharts.Chart({ credits: { enabled: false }, chart: { renderTo: 'container', exporting: { enabled: false }, events: { redraw: function(event) { colorSlices(); } }, plotBackgroundColor: null, plotBorderWidth: null, plotShadow: false, shadow: true }, tooltip: { pointFormat: '', percentageDecimals: 1 }, legend: { useHTML: true, align: 'right', verticalAlign: 'middle', itemWidth: 260, borderColor: '#fff', width: 260, labelFormatter: function() { return '&lt;div class="legend-item"&gt;' + this.name +'&lt;/div&gt;'; } }, title: { text: "" }, plotOptions: { pie: { allowPointSelect: true, size:'100%', cursor: 'pointer', showInLegend: true, shadow: true, dataLabels: { enabled: true, distance: -40, useHTML: true, style: { width: '100px' }, color: '#fff', connectorColor: '#000000', formatter: function() { return '&lt;span class="slice"&gt;' + Highcharts.numberFormat(this.percentage,1,".",",") +' %&lt;/span&gt;'; } } } }, series: [{ type: 'pie', name: 'Income Investments', data: [ ['Other Industries', 19.3], ['Media', 16.0], ['Materials', 13.6], ['Software &amp; Services', 10.2], ['Retailing', 7.9], ['Capital Goods', 6.5], ['Healthcare Equipment &amp; Services', 6.0], ['Insurance', 5.7], ['Technology Hardware &amp; Equipment', 5.4], ['Consumer Services', 4.8], ['Telecommunication Services', 4.7] ] }], colors: [ '#132f55', '#4d6d8a', '#7f95aa', '#b2bfcb', '#d1dae2', '#e5eaef', '#7f7f7f', '#9e9e9e', '#c9c9c9', '#bcbdc0', '#eeefef' ] }); }) </code></pre> <p>I ultimately want each slice in my pie to have incremental classes like: - slice-1 - slice-2 - slice-3</p> <p>I've kind of got this working, but only when the chart resizes. I've tried to trigger my custom function in the load event, but nothing happens.</p> <p>My fiddle: <a href="http://jsfiddle.net/6PbbR/262/" rel="nofollow">http://jsfiddle.net/6PbbR/262/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload