Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在图表线上方添加渐变色?_Javascript_Jquery_Css_Charts_Highcharts - Fatal编程技术网

Javascript 如何在图表线上方添加渐变色?

Javascript 如何在图表线上方添加渐变色?,javascript,jquery,css,charts,highcharts,Javascript,Jquery,Css,Charts,Highcharts,通过反转y轴,我在图表区域的顶部得到渐变色。检查下面的图片 yAxis: { reversed: true, showFirstLabel: false, showLastLabel: true } 我不想反转y轴,如果我反转y轴,我的图表也会反转。我想要渐变色,它在图表线的顶部,而不使用这个反向的Y轴。向我推荐highcharts中的其他选项 谁能帮我解决这个问题 我正在处理实时随机数据。在这

通过反转y轴,我在图表区域的顶部得到渐变色。检查下面的图片

   yAxis: {
            reversed: true,
            showFirstLabel: false,
            showLastLabel: true
         }

我不想反转y轴,如果我反转y轴,我的图表也会反转。我想要渐变色,它在图表线的顶部,而不使用这个反向的Y轴。向我推荐highcharts中的其他选项

谁能帮我解决这个问题

我正在处理实时随机数据。在这种情况下,只有数据经过的区域才应该获得渐变颜色,聊天中数据以外的空白区域不应该获得渐变颜色

根据@DaMaxContent-answer,输出将如下图所示

我不想让梯度填充图表数据的其他区域。您能帮我解决这个问题吗。

故障: 您可以使用gridZindex和backgroundColor/fillColor属性 产生预期的效果。唯一的问题是网格必须 显示在图形上。以下是解决方案:

下面是它背后的代码:

chart: {
  type: 'area',
  backgroundColor: { //<<--that is what you are using as fill color
    linearGradient : {
      x1: 0,
      y1: 1,
      x2: 0,
      y2: 0
    },
    stops : [
      [0, Highcharts.getOptions().colors[0]],
      [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
    ]
  }
},

rangeSelector: {
  selected: 1
},

title: {
  text: 'AAPL Stock Price'
},

yAxis: {
  reversed: false,
  showFirstLabel: false,
  showLastLabel: true,
  gridZIndex: 1000      //<<--grid Z index is used to display grid lines over the graph instead of under it
},

series: [{
  name: 'AAPL Stock Price',
  data: data,
  threshold: null,
  fillColor : "#fff", //<<--fill color under the line to simulate effect
  zIndex: 1000,
  tooltip: {
  valueDecimals: 2
  }
}]
图表:{
类型:'区域',

背景颜色:{//您在这里问了一个问题:如果您有其他信息要提供,请更新您现有的帖子。如果您喜欢这个答案,请在原始问题上选择它,因为这个问题可能会像这样结束(除了到边缘,而不是特定时间):应该do@jlbriggs,对不起,我是stackoverflow新手。我在这里更新了我的问题:@DaMaxContent:我在原始问题中更新了我的问题。为什么不使用
plotBackgroundColor
?就像原始问题中提到的@jlbriggs一样(让我们将此问题视为重复问题).plotBackgroundColor仅适用于主情节。它不会同时适用于两个情节。您好,感谢您的回复。这对我非常有帮助。但我使用的是实时随机数据,并在我的问题中进行了简要解释,请查看并帮助我解决此问题。