shaping triangle and sawtooth wave for line chart - Javascript highcharts

Javascript examples for highcharts:Line Chart

Description

shaping triangle and sawtooth wave for line chart

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 () {//from   w w w .  j  av  a  2s .com
    var chart;
    $(document).ready(function() {
        var myArray = [];
        var myVals = [];
        var mytrin = [];
        ti = 2.0 * Math.PI * (880 / 44100);
        theta = 0;
        console.log(ti);
        for(i = 0; i <100; i++){
            myArray.push(i);
            //console.log(theta);
            var ke = value = 1-Math.abs((theta%4)-2);
            mytrin.push(ke);
            theta = theta + ti;
        }
        console.log(myVals)
        chart = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                type: 'line',
                marginRight: 130,
                marginBottom: 25
            },
            title: {
                text: 'Monthly Average Temperature',
                x: -20 //center
            },
            subtitle: {
                text: 'Source: WorldClimate.com',
                x: -20
            },
            xAxis: {
                categories: myArray,
            minTickInterval: 5
            },
            yAxis: {
                title: {
                    text: 'Temperature (?C)'
                },
                plotLines: [{
                    value: 0,
                    width: 1,
                    color: '#808080'
                }]
            },
            tooltip: {
                formatter: function() {
                        return '<b>'+ this.series.name +'</b><br/>'+
                        this.x +': '+ this.y +'?C';
                }
            },
            legend: {
                layout: 'vertical',
                align: 'right',
                verticalAlign: 'top',
                x: -10,
                y: 100,
                borderWidth: 0
            },
            series: [{name: 'square', data: mytrin}]
        });
    });
});

      </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