Set chart option in Javascript - Javascript highcharts

Javascript examples for highcharts:Chart Option

Description

Set chart option in Javascript

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.js"></script> 
      <style id="compiled-css" type="text/css">

@media(max-width: 300px){
   html{//w  ww  . j a va 2s .c om
      background-color: blue !important;
   }
   #highcharts-0 svg g g path{
      fill: green !important;
   }
}


      </style> 
      <script type="text/javascript">
$(function () {
    $('#container').highcharts({
        chart: {
            type: 'spline'
        },
        title: {
            text: 'Monthly Average Temperature'
        },
        subtitle: {
            text: 'Source: WorldClimate.com'
        },
        xAxis: {
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
                'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
        },
        yAxis: {
            title: {
                text: 'Temperature'
            },
            labels: {
                formatter: function () {
                    return this.value + '?';
                }
            }
        },
        tooltip: {
            crosshairs: true,
            shared: true
        },
        plotOptions: {
            spline: {
                marker: {
                    radius: 4,
                    lineColor: '#666666',
                    lineWidth: 1
                }
            }
        },
        series: [{
            name: 'Tokyo',
            marker: {
                symbol: 'square'
            },
            data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, {
                y: 26.5,
                marker: {
                    symbol: 'url(https://www.highcharts.com/demo/gfx/sun.png)'
                }
            }, 23.3, 18.3, 13.9, 9.6]
        }]
    });
    if ($(window).width() < 500) {
        var chart = $('#container').highcharts();
        chart.options.plotOptions.spline.marker.radius = 8;
        chart.series[0].update();
    }
    $( window ).resize(function() {
        var chart = $('#container').highcharts();
        if ($(window).width() < 500) {
           chart.options.plotOptions.spline.marker.radius = 8;
           chart.series[0].update();
        }
        else {
           chart.options.plotOptions.spline.marker.radius = 4;
           chart.series[0].update();
        }
    });
});

      </script> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <script src="https://code.highcharts.com/modules/exporting.js"></script> 
      <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>  
   </body>
</html>

Related Tutorials