<html>
<head>
<title>Highcharts test 1 (2 つの csv ファイルからデータを読み込んで表示)</title>
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="../js/highcharts.js"></script>
<script type="text/javascript" src="../js/modules/exporting.js"></script>
<script type="text/javascript" src="highcharts1.js"></script>
</head>
<body>
<div id="container0" style="height: 400px; margin: 0;"></div>
</body>
</html>
highcharts1.js
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container0',
type: 'line',
zoomType: 'xy',
},
title: {
text: 'test chart 1',
},
xAxis: {
categories: []
},
yAxis: {
},
series: []
}
$.get('highcharts1_data2011.csv', function(data) {
// Split the lines
var lines = data.split('\n');
// Iterate over the lines and add categories or series
$.each(lines, function(lineNo, line) {
var items = line.split(',');
// header line contains categories
if (lineNo == 0) {
$.each(items, function(itemNo, item) {
options.xAxis.categories.push(item);
});
}
// the rest of the lines contain data with their name in the first position
else {
var series = {
name: '2011',
data: []
};
$.each(items, function(itemNo, item) {
series.data.push(parseFloat(item));
});
options.series.push(series);
}
});
});
$.get('highcharts1_data2012.csv', function(data) {
// Split the lines
var lines = data.split('\n');
// Iterate over the lines and add categories or series
$.each(lines, function(lineNo, line) {
var items = line.split(',');
// header line contains categories
if (lineNo == 0) {
$.each(items, function(itemNo, item) {
options.xAxis.categories.push(item);
});
}
// the rest of the lines contain data with their name in the first position
else {
var series = {
name: '2012',
data: []
};
$.each(items, function(itemNo, item) {
series.data.push(parseFloat(item));
});
options.series.push(series);
}
});
// Create the chart
var chart = new Highcharts.Chart(options)
});
});
highcharts1_data2011.csv
Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec 5.1,7.0,8.1,14.5,18.5,22.8,27.3,27.5,25.1,19.5,14.9,7.5highcharts1_data2012.csv
Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec 4.8,5.4,8.8,14.5,19.6,21.4,26.4,29.1,26.2,19.4,12.7,7.3出力結果
sample04 (fc2 に置いてあるテストページに飛びます)
はじめまして。Highchartsを使ってグラフを作るために勉強をしているものです。
返信削除参考にさせてもらいたく思います。
このサンプルは2つのcsvですが、1つのcsvファイルに複数データが入っている場合でも同じように動くのでしょうか?
a,b,c,d,e,f,g ←タイトル
1,2,3,4,5,6,8 ←データ
7,6,5,4,3,2,1 ←データ
・・・・
ご教授のほどよろしくお願いします。
こちらを参照してください
削除[Highcharts]csvファイルからデータを取り込んで表示するグラフ
遅くなりました。
削除ありがとうございます。
サンプルをコピーして動作させようと思ったのですが、
何も動かないのです・・・
highcharts.js
modules/exporting.js
2つ同じようにセッティングしたのですが、真っ白で・・・
何が悪いのかが分からない状況です・・・。
csvも同じ階層に置いています。
よろしくお願いします。
以下の様なフォルダ構成になっていますか?
削除+-- js/
| +-- adapters/
| +-- modules/
| +-- themes/
| +-- highcharts.js
| +-- highcharts.src.js
+-- test/
+-- highcharts1.html
+-- highcharts1.js
+-- highcharts1_data2011.csv
+-- highcharts1_data2012.csv
返事が遅くなってすみません。
削除フォルダ構成が違っていたので教えてもらったようにしたら
動きました。ありがとうございます。