changing color of area depending on y-value in area chart - Javascript highcharts

Javascript examples for highcharts:Chart Value

Description

changing color of area depending on y-value in area chart

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Highcharts Demo</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
      <script type="text/javascript">
$(function () {// w  ww . j a v a  2  s.co m
    $("#container1").highcharts({
        series: [{
            threshold: 2,
            negativeColor: 'red',
            color: 'green',
            type: 'area',
            data: [1, 2, 2, 1, 3, 3, 2, 3, 2, 1, 1, 3, 1, 1]
        }]
    });
    $("#container2").highcharts({
        series: [{
            threshold: 1,
            color: {
                linearGradient: {
                    x1: 0,
                    x2: 0,
                    y1: 0,
                    y2: 1
                },
                stops: [
                    [0, 'green'],
                    [0.49, 'green'],
                    [0.5, 'red'],
                    [1, 'red']
                ]
            },
            type: 'area',
            data: [1, 2, 2, 1, 3, 3, 2, 3, 2, 1, 1, 3, 1, 1]
        }]
    });
});

      </script> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <div id="container1" style="height: 300px; width: 400"></div> 
      <div id="container2" style="height: 300px; width: 400"></div>  
   </body>
</html>

Related Tutorials