Chapter 2: Expanding Color with Gradients (3)

linear gradient in vertical direction with ratio values. Both background and 2 bars have linear gradient

by JoeKuan

HTML

<script type="text/javascript" src="http://code.highcharts.com/highcharts.js"></script>
<body>
<div style="border: 2px solid #a1a1a1; width:350; height: 150; border-radius: 3px; margin: 5px 60px 5px 5px; " id='container'></div>
</body>

JavaScript

var chart;
    $(document).ready(function() {

var colorGradient = {
    linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
                  stops: [ [ 0, '#4572A7' ],
                           [ 1, '#C7D5E5' ] ]
};

        chart = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                spacingRight: 30,
                height: 300
            },
            title: {
                text: 'Market Data: Nasdaq 100'
            },
            subtitle: {
                text: '2011 - 2012'
            },
            xAxis: {
                categories: [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 
                              'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ],
                labels: {
                    y: 17
                },
               gridLineDashStyle: 'dot',
               gridLineWidth: 1,
               lineWidth: 2,
               lineColor: '#92A8CD',
               tickWidth: 3,
               tickLength: 6,
               tickColor: '#92A8CD',
               // Need extra because there is a bug in Highcharts
               minPadding: 0.04,
               offset: 1,
            },
            yAxis: {
               title: {
                  text: 'Volume'
               },
                minorGridLineColor: '#D8D8D8',
                minorGridLineDashStyle: 'dashdot',
                gridLineColor: '#8AB8E6',
                alternateGridColor: {
                    linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
                    stops: [ [0, 'red' ],
                             [0.2, 'orange' ],
                             [0.5, 'yellow'] ,
                             [0.8, 'green'] ,
                             [1, 'lime'] ]
                },
                lineWidth: 2,
                lineColor: '#3D96AE',
                tickWidth: 3,
                tickLength: 6,
                tickColor: '#3D96AE',
            },
            credits: {
                enabled: false
         ...