【问题标题】:Set Opacity using CSS on pie-chart in Highchart在 Highchart 的饼图中使用 CSS 设置不透明度
【发布时间】:2019-04-28 17:21:23
【问题描述】:

目前我面临一个问题,我需要使用 Highchart 在饼图上手动设置不透明度。如果您知道要分配给切片的颜色,则以下解决方案可以正常工作。但是如果颜色是从一个通用的调色板中挑选出来的,就没有办法给出不透明度。它总是需要 0。任何人都可以帮我解决这个问题。

$(function () {
    $('#container').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false,
        },
        title: {
            text: 'Browser market shares at a specific website, 2010'
        },
        tooltip: {
    	    pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
            fillOpacity: 0.5,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    color: '#000000',
                    connectorColor: '#000000',
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %'
                }
            }
        },
        series: [{
            type: 'pie',
            name: 'Browser share',
            data: [
                ['Firefox',   45.0],
                ['IE',       26.8],
                {
                    name: 'Chrome',
                    y: 12.8,
                    sliced: true,
                    selected: true,
                    color: 'rgba(150,100,50,0.1)'
                },
                ['Safari',    8.5],
                ['Opera',     6.2],
                ['Others',   0.7]
            ]
        }]
    });
});
    
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>

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

【问题讨论】:

    标签: javascript highcharts


    【解决方案1】:

    您可以使用attr方法设置opacity

            events: {
                load: function() {
                    var points = this.series[0].points;
    
                    points[1].graphic.attr({
                        opacity: 0.4
                    })
                }
            }
    

    现场演示:http://jsfiddle.net/BlackLabel/59mye8kn/

    API:https://api.highcharts.com/class-reference/Highcharts.SVGElement#attr

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-17
      • 2023-03-09
      • 2012-01-26
      • 1970-01-01
      • 2010-12-17
      • 1970-01-01
      • 1970-01-01
      • 2013-11-08
      相关资源
      最近更新 更多