$(function () { var seriesOptions = [], seriesCounter = 0, //names = ['TEMP']; names = ['SG', 'TEMP', 'STC-1000']; /** * Create the chart when all data is loaded * @returns {undefined} */ function createChart() { Highcharts.setOptions({ global: { timezoneOffset: beerData.gmt * 60 //EST offset } }); var chart =Highcharts.stockChart('container1', { rangeSelector: { enabled:false }, navigator: { enabled: false }, scrollbar: { enabled: false }, credits: { enabled: false }, chart: { zoomType: 'x' }, title: { text: beerData.name }, // subtitle: { // text: 'My custom subtitle'+beerData.batchnr // }, plotOptions: { series: { turboThreshold:50000, dataGrouping: { smoothed: true, forced: true, units: [ ['hour', [beerData.graphview]] ] } } }, yAxis: [{ // Primary yAxis labels: { format: '{value:.1f}', style: { color: Highcharts.getOptions().colors[0] } }, // min: 1, // max: beerData.maxstyleYaxsis, tickInterval: 1, title: { text: beerData.tmp, style: { color: Highcharts.getOptions().colors[0] } }, plotBands: [{ color: '#ffffe6', from: beerData.minstyle, // Start of the plot band to: beerData.maxstyle, // End of the plot band label: { text: beerData.styleid+": "+beerData.minstyle+"-"+beerData.maxstyle+" "+beerData.sclstyle, verticalAlign: 'bottom', y:-5 } }], opposite: true }, { // Secondary yAxis title: { text: 'Final Gravity', style: { color: Highcharts.getOptions().colors[3] } }, labels: { format: '{value:.3f}', style: { color: Highcharts.getOptions().colors[3] } }, min: 0.995, plotLines: [{ color: 'green', width: 2, value: beerData.targetFG, dashStyle: 'dashdot', label: { text: beerData.fg + ' ('+beerData.targetFG+')', textAlign: 'left' } }], opposite: false }], tooltip: { headerFormat: '{point.key}
', pointFormat: '{series.name}: {point.y:.3f}
', valueDecimals: 1, split: true }, series: seriesOptions }); } // End Functions $.each(names, function (i, name) { $.getJSON('/api.php?scale=' + name.toLowerCase() + '.json&batch=' + beerData.batchnr + '&callback=?', function (data) { console.log('/api.php?scale=' + name.toLowerCase() + '.json&batch=' + beerData.batchnr + '&callback=?'); if (name == "TEMP"){ var yAxis = 0; var color = '#7cb5ec'; var id = "temp"; var Style = 'solid'; var Tracking= true; } if (name == "SG"){ var yAxis = 1; var color = "#ff0000"; var id = "sg"; var Style = 'solid'; var Tracking= true; } if (name == "STC-1000"){ var yAxis = 0; var color = '#7cb5ec'; var id = "stc"; var Style = 'dot'; var Tracking=false; } seriesOptions[i] = { name: name, data: data, allowDecimals: true, valueDecimals: 1, color: color, dashStyle: Style, yAxis: yAxis, enableMouseTracking: Tracking, id: id }; seriesCounter += 1; if (seriesCounter === names.length) { createChart(); } }); }); });