Add function to chart axis object - Javascript highcharts

Javascript examples for highcharts:Chart Axis

Description

Add function to chart axis object

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://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
      <script type="text/javascript">
$(function() {/* w w w .  ja  v  a 2  s .co  m*/
    Highcharts.Axis.prototype.init = (function (func) {
      return function (chart, userOptions) {
         func.apply(this, arguments);
         if (this.categories) {
            this.userCategories = this.categories;
            this.categories = undefined;
            this.labelFormatter = function () {
               return this.axis.userCategories[this.value];
            };
         }
      };
   }(Highcharts.Axis.prototype.init));
    var chart;
    $(document).ready(function() {
        chart = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                height: 300,
                type: 'areaspline'
            },
            credits: {
                enabled: false
            },
            legend: {
                enabled: false,
                layout: 'horizontal'
            },
            plotOptions: {
                areaspline: {
                    marker: {
                        enabled: false
                    }
                }
            },
            title: {
                text: ''
            },
            tooltip: {
                shared: true
            },
            xAxis: {
                categories: ['do 20.09', 'vr 21.09', 'za 22.09', 'zo 23.09', 'ma 24.09', 'di 25.09', 'wo 26.09'],
                endOnTick: true,
                labels: {
                    align: 'right',
                    rotation: -45,
                    y: 20
                },
                maxPadding: 0,
                minPadding: 0,
                startOnTick: true,
                title: {
                    align: 'low',
                    margin: 10,
                    text: ''
                },
                type: 'linear'
            },
            yAxis: {
                labels: {
                    formatter: function() {
                        return '?' + this.value;
                    }
                },
                min: 0,
                showFirstLabel: false,
                title: {
                    text: ''
                }
            },
            series: [{
                data: [1.3461, 1.3374, 0.3744, 0.3744, 1.2552, 1.0654, 1.6595],
                name: 'AVG',
                color: '#F7F7F7'},
            {
                data: [2.4400, 2.4112, 0.3744, 0.3744, 2.4238, 1.8185, 2.5662],
                name: 'NOW',
                color: '#BDE587'}]
        });
    });
});

      </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: 400px; height: 400px; margin: 0 auto"></div>  
   </body>
</html>

Related Tutorials