複数の変数を折れ線グラフとしてハイチャートに配置する必要があります。変数の数が非常に多いため、データを取得して動的にグラフ化できる必要があります。
すべてのサーバーの CPU 使用率を 1 つのグラフに異なる線で表示する必要がある複数のサーバーがあります。私のデータは、SQLクエリから次のようになります。
ServerName DateTime CPU
ServerA 1/2/2013 12:00:00 30
ServerA 1/2/2013 01:00:00 20
ServerA 1/2/2013 02:00:00 50
ServerB 1/2/2013 12:00:00 30
ServerB 1/2/2013 01:00:00 30
ServerB 1/2/2013 02:00:00 5
ServerC 1/2/2013 01:00:00 10
serverC 1/2/2013 02:00:00 50
ServerC 1/2/2013 03:00:00 70
以下のコードを見ていましたが、データが見えないため、実際には何も作成できません。上記の sql クエリの結果を、highstock チャートを使用して複数折れ線系列チャートに追加するにはどうすればよいですか?
$(function() {
var seriesOptions = [],
yAxisOptions = [],
seriesCounter = 0,
names = ['MSFT', 'AAPL', 'GOOG'],
colors = Highcharts.getOptions().colors;
$.each(names, function(i, name) {
$.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename='+ name.toLowerCase() +'-c.json&callback=?', function(data) {
seriesOptions[i] = {
name: name,
data: data
};
// As we're loading the data asynchronously, we don't know what order it will arrive. So
// we keep a counter and create the chart when all the data is loaded.
seriesCounter++;
if (seriesCounter == names.length) {
createChart();
}
});
});
// create the chart when all data is loaded
function createChart() {
$('#container').highcharts('StockChart', {
chart: {
},
rangeSelector: {
selected: 4
},
yAxis: {
labels: {
formatter: function() {
return (this.value > 0 ? '+' : '') + this.value + '%';
}
},
plotLines: [{
value: 0,
width: 2,
color: 'silver'
}]
},
plotOptions: {
series: {
compare: 'percent'
}
},
tooltip: {
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>',
valueDecimals: 2
},
series: seriesOptions
});
}
});