簡體   English   中英

JavaScript餅圖顏色

[英]Javascript Pie Chart Colors

有什么辦法可以更改此餅圖代碼中的顏色? 如果沒有,我是否可以添加一些代碼,讓我為餡餅的每個切片選擇特定的顏色(最好是RGB或十六進制)?

JSFiddle: http : //jsfiddle.net/hdbmuwa2/

謝謝!

Java:

$(function () {
// Create the chart
$('#container').highcharts({
    credits: {
        enabled: false
    },
    chart: {
plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false,
        type: 'pie'
    },
    title: {
        text: 'Green Up Amount Recycled'
    },
    subtitle: {
        text: 'Click the Recycled Materials slice for more information.'
    },
   plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: false
                },
                showInLegend: true
            }
        },
    tooltip: {
        headerFormat: '<span style="font-size:11px">{series.name}</span><br>',
        pointFormat: '<span style="color:{point.color}">{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>'
    },
    series: [{
        name: "Materials",
        colorByPoint: true,
        data: [{
            name: "Landfill - 45,821 lbs",
            y: 23.73,
        }, {
            name: "Recycled Materials - 147,276 lbs",
            y: 76.27,
            drilldown: "Recycled Materials"
        }]
    }],
    drilldown: {
        series: [{
            name: "Recycled Materials",
            id: "Recycled Materials",
            data: [
                ["Tent Frames and Chairs - 6,400 lbs", 4.35],
                ["Aluminum Cans - 28,950 lbs", 19.66],
                ["Plastic PET Bottles - 36,420 lbs", 24.73],
                ["Glass - 40,950 lbs", 27.8],
                ["Cardboard - 30,000 lbs", 20.37],
                ["Solo Cups - 4,556 lbs", 3.09],
            ]
        }]
    }
});
});

HTML:

    <script src="http://code.highcharts.com/highcharts.js"></script>
    <script src="http://code.highcharts.com/modules/exporting.js"></script>
    <script src="http://code.highcharts.com/modules/data.js"></script>
    <script src="http://code.highcharts.com/modules/drilldown.js"></script>

<div id="container" style="min-width: 500px; max-width: 500px; height: 500px; margin: 0 auto"></div>

是的你可以!

在plotOptions:pie對象中添加要顯示的顏色的屬性數組。

 plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: false
                },
                showInLegend: true,
                colors: ['#00e500', '#004400']
            },

        },

您可以在此處查看其工作示例: http : //jsfiddle.net/jbs01j7k/

您可以在此處查看更多樣式和其他選項: http : //api.highcharts.com/highcharts#plotOptions.pie.colors

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM