简体   繁体   English

如何在HighCharts中更改单个气泡的颜色和不透明度?

[英]How do I change an individual bubble's color and opacity in HighCharts?

I have created a HighCharts BubbleChart and am trying to make adjustment to the color and opacity of an individual bubble. 我创建了一个HighCharts BubbleChart,并试图对单个气泡的颜色和不透明度进行调整。 I seem to be able to adjust the color but the opacity stays fixed at 0.5 (When I view the Bubble's properties in the browser's DOM Inspector). 我似乎能够调整颜色,但不透明度保持固定为0.5(当我在浏览器的DOM Inspector中查看Bubble的属性时)。 This seems to be some sort of HighCharts default (for the whole series?), how do I modify it on an individual basis? 这似乎是某种HighCharts默认值(适用于整个系列吗?),如何单独修改它?

Below is a minimal HighCharts example showing the issue. 以下是显示问题的最小HighCharts示例。

Also, the same code on Plunkr https://plnkr.co/edit/Wl7HhVgwOffN1CL3DxtC 此外,Plunkr上的相同代码https://plnkr.co/edit/Wl7HhVgwOffN1CL3DxtC

If you view the yellow bubble in the DOM Inspector you'll see it has an opacity of 0.5 although in the code it is clearly set to 1. 如果在DOM Inspector中查看黄色气泡,您将看到它的不透明度为0.5,尽管在代码中明确将其设置为1。

$(function () {
    $('#container').highcharts({
        chart: {
        type: 'bubble',
        plotBorderWidth: 1,
        zoomType: 'xy'
    },

    title: {
        text: 'Highcharts Bubbles'
    },

    xAxis: {
        gridLineWidth: 1
    },

    yAxis: {
        startOnTick: false,
        endOnTick: false
    },

    plotOptions: {
        bubble: {
            minSize: 3,
            maxSize: 50
        }
    },

    series: [{
        data: [
          {x:9,y:81,z:63},
          {x:98,y:5,z:89,color:"rgba(255,255,0,1)"},
          {x:51,y:50,z:73}
        ],
    }]

    });
});

only when fillOpacity is set to 1 you can change the opacity of a color using fillColor for set it. 仅当fillOpacity设置为1时,您才可以使用fillColor设置颜色来更改颜色的不透明度。

Maybe you want to read this: https://github.com/highcharts/highcharts/issues/4278 也许你想读这个: https : //github.com/highcharts/highcharts/issues/4278

Edit for add this example: 编辑以添加此示例:

{ x:51,
  y:50,
  z:73,
  color: 'rgba(255,0,0,0.5)',
  marker: {
    fillColor:0,
    fillOpacity:1
  }
}

--- Edit --- -编辑-

After a little discusion and review of the library this appear to be the only trick to made this work has expected: 在对库进行一点讨论和审查之后,这似乎是完成这项工作的唯一技巧:

https://plnkr.co/edit/MvAC94ovCwvPQCe3tZo3?p=preview https://plnkr.co/edit/MvAC94ovCwvPQCe3tZo3?p=preview

Extract: 提取:

series: [{
            data: [
              {x:9,y:81,z:63},
              { x:98,
                y:5,
                z:89
              },
              { x:51,
                y:50,
                z:73,
                color: {
                    linearGradient: { x1: 0, x2: 0, y1: 0, y2: 1 },
                    stops: [
                        [0, 'rgba(255,255,0,0.1)'],
                        [1, 'rgba(255,255,0,0.1)']
                    ]
                }
              }
            ],
        }]

How about this: 这个怎么样:

series: [{
    data: [
      {x:9,y:81,z:63},
      {x:98,y:5,z:89, color: 'yellow'},
      {x:51,y:50,z:73}
    ],

http://jsfiddle.net/3mtmmfzx/52/ http://jsfiddle.net/3mtmmfzx/52/

Edit: Would 100% opacity and 50% (the default) be enough to switch between? 编辑:100%的不透明度和50%(默认值)是否足以在之间进行切换?

If so you could just switch between 'yellow' and 'rgb(255,255,0)' 如果是这样,您可以在'yellow''rgb(255,255,0)'之间切换

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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