Highcharts pie chart slice colour intensity using

2019-08-15 04:30发布

I am trying to achieve the same thing as seen here:

http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/treemap-coloraxis

Except with a pie chart instead.

I have it set up like so:

 $('#expenditurePie').highcharts({
            chart: {
                plotBackgroundColor: null,
                plotBorderWidth: null,
                plotShadow: false,
                backgroundColor: '#121212',
                height: 322,
                className: 'summary-chart-right'
            },
            title: null,
            tooltip: {
                pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
            },
            plotOptions: {
                pie: {
                    allowPointSelect: true,
                    borderColor: '#000',
                    cursor: 'pointer',
                    dataLabels: false
                }
            },
            colorAxis: {
                minColor: '#FFFFFF',
                maxColor: '#FF0000'
            },
            series: response
        });

A sample of response data:

...
{name: "Leisure", y: 143.55, colorValue: 3}
...

It isn't working and the pie chart colours are their default.

How can I do this?

1条回答
霸刀☆藐视天下
2楼-- · 2019-08-15 04:41

According to the docs, colorValue is only available on TreeMaps.

However, you can do a similar thing without much difficulty. Instead of colorValue, use color, and then call to a function to get a value. Here's a quick-and-dirty example that can be improved in various ways depending on exactly what behavior you want:

var getColor = function (step,stepCount) {
    var scaledHex = Math.floor(255*step/(stepCount+1)).toString(16);
    console.log(scaledHex);
    return '#FF'+scaledHex+scaledHex;
};

And

...
{name: "Leisure", y: 143.55, color: getColor(1,3)}
...

http://jsfiddle.net/8Lnzcnx6/

查看更多
登录 后发表回答