Peter Pik
Peter Pik

Reputation: 11193

applying stock chart style in highchart

i've so far created an high chart which into my page. However i want to apply different colors if they are below or above 0. I've plotted a line on 0, but cant seem to change the colors so it looks like following:

enter image description here

Here is my code

$(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>

Upvotes: 0

Views: 107

Answers (1)

Mark
Mark

Reputation: 108567

You are looking for the negativeColor and negativeFillColor options.

Here's a link to the official example.

And your code updated:

$(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'
    }]
  });
});
<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>

Upvotes: 1

Related Questions