【问题标题】:Highcharts - Area fillOpacity is mixing on multiple area chartsHighcharts - 区域填充不透明度在多个区域图表上混合
【发布时间】:2016-04-19 03:29:44
【问题描述】:

我正在使用 Highcharts(面积图)...

我正在尝试将线条颜色用作#f68936,将区域背景颜色用作10% of opacity 来为其颜色。当我使用一张图表时,它按预期工作。当我在组合更多区域时遇到前图不透明背景的问题。

绿色背景不透明度与红色混合并显示不同的颜色:(

如何显示原始颜色 (background opacity) 虽然它有多个区域。

Online demo


预期结果:



我得到的结果如下:


$(function () {
  // Everything in common between the charts
  var commonOptions = {
    colors: ['#f68936', '#70ba47', '#33b5e6', '#fd8f40', '#e7ca60', '#40abaf', '#f6f7f8', '#e9e9eb'],
    chart: {
      style: {
        fontFamily: 'Roboto Light',
        fontWeight: 'normal',
        fontSize: '12px',
        color: '#585858',
      }
    },
    title: {
      text: null
    },
    subtitle: {
      text: null
    },
    credits: {
      enabled: false
    },
    exporting: {
      enabled: false
    },
    xAxis: {
      title: {
        style: {
          fontFamily: 'Roboto',
          color: "#bbb",
        }
      },
      labels: {
        style:{ color: '#bbb' },
      },
      lineWidth: 1,
      tickLength: 0,
    },
    yAxis: {
      title: {
        style: {
          fontFamily: 'Roboto',
          color: "#bbb",
        }
      },
      offset:-6,
      labels: {
        style:{ color: '#bbb' },
        //format:'{value}K',
      },
      tickInterval: 100,
      lineWidth: 1,
      gridLineDashStyle: 'dash',
    },
    series: [{
      //backgroundColor: "rgba(0 ,0, 0, 1)",
    }],

    // Area Chart
    plotOptions: {
      series: {
        fillOpacity: 0.1
      },
      area: {
        lineWidth: 1,
        marker: {
          lineWidth: 2,
          symbol: 'circle',
          fillColor: 'white',
          radius:3,
        },
        legend: {
          radius: 2,
        }
      }
    },
    tooltip: {
      useHTML: true,
      shared: true,
      backgroundColor: '#5f5f5f',
      borderWidth: 0,
      style: {
        padding:10,
        color: '#fefefe',
      }
    },
    legend: {
      itemStyle: {
        fontFamily: 'Roboto Light',
        fontWeight: 'normal',
        fontSize: '12',
        color: '#666666',
      },
      marker: {
        symbol: 'square',
        verticalAlign: 'middle',
        radius: '4',
      },
      symbolHeight: 6,
      symbolWidth: 6,
    },
  };

  // -----------------------------------------------------
  $('.areaChartTwoWay').each(function() {
    $(this).highcharts(Highcharts.merge(commonOptions, {
      chart: { type: 'area' },
      xAxis: {
        title: { text: 'Date', },
        type: 'datetime',
        dateTimeLabelFormats: {
          day: '%eth %b'
        },
      },
      yAxis: {
        title: { text: 'Count', },
      },
      series: [{
        name: 'Forwards',
        color: '#f68936',
        marker: { lineColor: '#f68936', fillColor: 'white', },
        data: [185, 290, 198, 220, 180, 140, 220, 335, 197, 240],
        legendIndex:1,
        pointStart: Date.UTC(2016, 2, 11),
        pointInterval: 24 * 3600 * 1000 // one day
      }, {
        name: 'Unique opens',
        color: '#70ba47',
        marker: { lineColor: '#70ba47', fillColor: 'white', },
        data: [90, 95, 98, 80, 70, 68, 85, 71, 64, 90],
        legendIndex:0,
        pointStart: Date.UTC(2016, 2, 11),
        pointInterval: 24 * 3600 * 1000 // one day
      }]
    }))

  });

  $('.highcharts-grid > path:last-child').remove();
  $('.highcharts-markers > path:last-child').remove();

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<div class="areaChartTwoWay" style="min-width: 150px; height: 250px; margin: 0 auto"></div>

【问题讨论】:

    标签: jquery highcharts


    【解决方案1】:

    您的帖子准确描述了不完全不透明度的工作原理。您还期待什么其他结果?

    如果您将某些内容的不透明度设置为小于 1,则其后面的任何内容都将部分可见 - 这意味着它将与前景色“混合”。

    这不仅是预期的行为,也是唯一可能的行为。这就是不完全不透明的意思。

    如果您希望您的系列与您的系列看起来的颜色相同在白色背景上不透明度小于 1,那么您需要确定该颜色实际上是什么,并将其设置为您的fillColor,不透明度为1。

    【讨论】:

      【解决方案2】:

      你有两种可能:

      【讨论】:

      • 您好 @Sebastian Bochan 感谢您的回答。但我正在动态计算 yAxis 值以设置最大 yAxis 值。在这种情况下,如果我使用此选项,我无法控制 yAxis 值 :( 请参考此链接:Demo is here for the same
      • 您可以使用堆叠或非堆叠系列完全控制 y 轴。问题是您的数据系列是否更有意义堆叠或不堆叠。
      猜你喜欢
      • 2019-12-15
      • 2013-04-28
      • 1970-01-01
      • 2011-04-22
      • 2017-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-27
      相关资源
      最近更新 更多