在highchart中应用股票图表样式

时间:2015-01-11 15:22:23

标签: javascript jquery html css highcharts

到目前为止,我已经在我的页面中创建了一个高图表。但是我想要应用不同的颜色,如果它们低于或高于0.我在0上绘制了一条线,但似乎无法改变颜色,所以看起来如下:

enter image description here

这是我的代码

$(function() {
  $('#chart-container').highcharts({
    title: {
      text: '',
      x: -20 //center
    },
    subtitle: {
      text: '',
      x: -20
    },
    exporting: {
      enabled: false
    },
    xAxis: {
      categories: ['Januar', 'Februar', 'Marts', 'April', 'Maj', 'Juni', 'Juli', 'Aug', 'Septemper', 'Oktober', 'November', 'December'],

      labels: {
        enabled: false
      },
    },
    yAxis: {
      gridLineWidth: 0,
      minorGridLineWidth: 0,
      title: {
        text: ''
      },
      labels: {
        enabled: false
      },
      plotLines: [{
        color: 'orange',
        width: 2,
        value: 0,
      }]
    },
    tooltip: {
      valueSuffix: 'Kr.'
    },
    legend: {
      layout: 'vertical',
      align: 'right',
      verticalAlign: 'middle',
      borderWidth: 0
    },
    credits: {
      enabled: false
    },
    series: [{
      showInLegend: false,
      name: 'Tokyo',
      data: [0.0, 6.9, 9.5, -14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
    }]
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.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="chart-container" style="min-width: 310px; height: 100%; margin: 0 auto"></div>

1 个答案:

答案 0 :(得分:1)

您正在寻找negativeColornegativeFillColor选项。

这是指向官方example的链接。

您的代码已更新:

&#13;
&#13;
$(function() {
  $('#chart-container').highcharts({
    title: {
      text: '',
      x: -20 //center
    },
    subtitle: {
      text: '',
      x: -20
    },
    exporting: {
      enabled: false
    },
    xAxis: {
      categories: ['Januar', 'Februar', 'Marts', 'April', 'Maj', 'Juni', 'Juli', 'Aug', 'Septemper', 'Oktober', 'November', 'December'],

      labels: {
        enabled: false
      },
    },
    yAxis: {
      gridLineWidth: 0,
      minorGridLineWidth: 0,
      title: {
        text: ''
      },
      labels: {
        enabled: false
      },
      plotLines: [{
        color: 'orange',
        width: 2,
        value: 0,
      }]
    },
    tooltip: {
      valueSuffix: 'Kr.'
    },
    legend: {
      layout: 'vertical',
      align: 'right',
      verticalAlign: 'middle',
      borderWidth: 0
    },
    credits: {
      enabled: false
    },
    series: [{
      showInLegend: false,
      name: 'Tokyo',
      data: [0.0, 6.9, 9.5, -14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6],
      color: 'purple',
      negativeColor: 'red'
    }]
  });
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.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="chart-container" style="min-width: 310px; height: 100%; margin: 0 auto"></div>
&#13;
&#13;
&#13;