简体   繁体   中英

Highcharts JS - share legend color between pie charts

I've two pie charts and i want to share their color of the legend items. The problem is that one pie has more elements in the legend as the other and their starts with different color.

I my case i can have very different legend items in two pie charts, but there are some equal and they should get the same color.

series: [{
            name: "Brands",
            colorByPoint: true,
            data: [{
                name: "Microsoft Internet Explorer",
                y: 56.33
            }, {
                name: "Chrome",
                y: 24.03,
                sliced: true,
                selected: true
            }, {
                name: "Firefox",
                y: 10.38
            }, {
                name: "Safari",
                y: 4.77
            }, {
                name: "Opera",
                y: 0.91
            }, {
                name: "Proprietary or Undetectable",
                y: 0.2
            }]
        }]

series: [{
            name: "Brands",
            colorByPoint: true,
            data: [{
                name: "Chrome",
                y: 24.03,
                sliced: true,
                selected: true
            }, {
                name: "Firefox",
                y: 20.38
            }, {
                name: "Safari",
                y: 4.77
            }, {
                name: "Opera",
                y: 0.91
            }, {
                name: "Proprietary or Undetectable",
                y: 0.2
            }]
        }]

jsfiddle example here

Color can be set per data point - slice. You could set them to be the same in both series for corresponding data points.

Example: http://jsfiddle.net/m2v2vyj2/1/

            }, {
                name: "Chrome",
                y: 24.03,
                color: '#c80'
            }, {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM