ラベル Highcharts の投稿を表示しています。 すべての投稿を表示
ラベル Highcharts の投稿を表示しています。 すべての投稿を表示

2013年2月6日水曜日

[Highcharts]Pie + csv

sample09.html
<html>
  <head>
    <title>Highcharts test 6 (Pie + 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="sample09.js"></script>
  </head>
  <body>
Pie + csv
    <div id="container0" style="height: 400px; width: 800px; margin: 0;"></div>
  </body>
</html>
sample09.js
$(document).ready(function() {
    $.get('sample09.csv', function(data) {
        var options = {
            chart: {
                renderTo: 'container0',
            },
            title: {
                text: 'Pie chart'
            },
            plotOptions: {
                pie: {
                    // データをクリックすると円グラフから少し離れて表示される
                    allowPointSelect: true,
                    // データ上にマウスを持っていった時に指マークで表示される
                    cursor: 'pointer',
                    // 各データを値付きで表示する
                    dataLabels: {
                        enabled: true,
                        formatter: function() {
                            // 小数点第 2 位まで表示する
                            return this.point.name + ': ' + (Math.round(this.percentage * 100) / 100) + ' %';
                        }
                    }
                }
            },
            series: [{
                type: 'pie',
                data: []
            }]
        }

        // Split the lines
        var lines = data.split('\n');

        // Iterate over the lins and add categories or series
        $.each(lines, function(lineNo, line) {
            if (line == '') {
                // No operation for No data line
                return true;
            }

            var items = line.split(',');

            switch (lineNo) {
            case 0:
                //header line contains categories
                $.each(items, function(itemNo, item) {
                    var d = [];
                    d.push(item);
                    options.series[0].data.push(d);
                });
                break;
            case 1:
            default:
                // the rest of the lines contain data with their name in the first position
                // 全体数を算出する
                var total = 0;
                $.each(items, function(itemNo, item) {
                    total += parseFloat(item);
                });

                var i = 0;
                $.each(items, function(itemNo, item) {
                    rate = (item / total) * 100;
                    options.series[0].data[i].push(parseFloat(rate));
                    i++;
                });
                break;
            }
        });

        // Create the chart
        var chart = new Highcharts.Chart(options)
    });
});
sample09.csv
Tanaka,Suzuki,Yamada
10,15,8
出力結果
sample09 (fc2 に置いてあるテストページに飛びます)

[Highcharts]Pie chart

sample08.html
<html>
  <head>
    <title>Highcharts test 5 (Pie chart)</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="sample08.js"></script>
  </head>
  <body>
Pie chart
    <div id="container0" style="height: 400px; width: 800px; margin: 0;"></div>
  </body>
</html>
sample08.js
$(document).ready(function() {
    var options = {
        chart: {
            renderTo: 'container0',
        },
        title: {
            text: 'Pie chart',
        },
        plotOptions: {
            pie: {
                // データをクリックすると円グラフから少し離れて表示される
                allowPointSelect: true,
                // データ上にマウスを持っていった時に指マークで表示される
                cursor: 'pointer',
                // 各データを値付きで表示する
                dataLabels: {
                    enabled: true,
                    formatter: function() {
                        return this.point.name + ': ' + this.percentage + ' %';
                    }
                },
            },
        },
        series: [{
            type: 'pie',
            name: '空気の構成比率',
            data: [
                ['窒素', 78.08],
                ['酸素', 20.95],
                ['アルゴン', 0.93],
                ['二酸化炭素', 0.035],
                ['その他', 0.005],
            ],
        }],
    }

    // Create the chart
    var chart = new Highcharts.Chart(options)
});
出力結果
sample08 (fc2 に置いてあるテストページに飛びます)

[Highcharts]Export する画像サイズを指定する

sample07.html
<html>
  <head>
    <title>Highcharts test 4 (Export する画像サイズを指定する)</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="sample07.js"></script>
  </head>
  <body>
Export する画像サイズを指定する
    <div id="container0" style="height: 400px; width: 800px; margin: 0;"></div>
    <div id="container1" style="height: 400px; width: 800px; margin: 0;"></div>
  </body>
</html>
sample07.js
$(document).ready(function() {
    $.get('sample07-1.csv', function(data) {
        var options = {
            chart: {
                renderTo: 'container0',
                type: 'line',
                zoomType: 'xy',
            },
            title: {
                // Title を 'exporting.width=default' にしていると画像ファイルへの出力でエラーが発生する
                text: 'exporting.width = default',
            },
            xAxis: {
                categories: [],
            },
            yAxis: {
            },
            series: []
        }

        // 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)
    });

    $.get('sample07-2.csv', function(data) {
        var options = {
            chart: {
                renderTo: 'container1',
                type: 'line',
                zoomType: 'xy',
            },
            title: {
                text: 'exporting.width = 1200',
            },
            xAxis: {
                categories: [],
            },
            yAxis: {
            },
            series: [],
            exporting: {
                width: 1200,
            }
        }

        // 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);
            }
        });

        // Create the chart
        var chart = new Highcharts.Chart(options)
    });
});
sample07-1.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.5
sample07-2.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
出力結果
sample07 (fc2 に置いてあるテストページに飛びます)

[Highcharts]縦棒グラフでX軸の項目名を角度を付けて表示する

sample06.html
<html>
  <head>
    <title>Highcharts test 3 (縦棒グラフ (column) で X 軸のラベルを角度を付けて表示する)</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="sample06.js"></script>
  </head>
  <body>
    <div id="container0" style="height: 400px; width: 800px; margin: 0;"></div>
  </body>
</html>
sample06.js
$(document).ready(function() {
    $.get('sample06.csv', function(data) {
        var options = {
            chart: {
                renderTo: 'container0',
                type: 'column',
                zoomType: 'xy',
            },
            title: {
                text: 'test chart 1',
            },
            xAxis: {
                categories: [],
                labels: {
                    rotation: -45,
                    align: 'right',
                }
            },
            yAxis: {
            },
            series: []
        }

        // 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);
            }
        });

        // Create the chart
        var chart = new Highcharts.Chart(options)
    });
});
sample06.csv
January,Feburary,March,April,May,Jun,July,August,September,October,November,December
4.8,5.4,8.8,14.5,19.6,21.4,26.4,29.1,26.2,19.4,12.7,7.3
出力結果
sample06 (fc2 に置いてあるテストページに飛びます)

[Highcharts]データを値付きで表示する

sample05.html
<html>
  <head>
    <title>Highcharts test 2 (描くデータに値を表示する)</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="highcharts2.js"></script>
  </head>
  <body>
    <div id="container0" style="height: 400px; margin: 0;"></div>
    <div id="container1" style="height: 400px; margin: 0;"></div>
  </body>
</html>
sample05.js
$(document).ready(function() {
    $.get('sample05-1.csv', function(data) {
        var options = {
            chart: {
                renderTo: 'container0',
                type: 'line',
                zoomType: 'xy',
            },
            title: {
                text: 'test chart 1',
            },
            xAxis: {
                categories: []
            },
            yAxis: {
            },
            plotOptions: {
                line: {
                    // 各データを値付きで表示する
                    dataLabels: {
                        enabled: true
                    },
                    // データ上にマウスポインタを置いた時に ToolTip が表示されないようにする
                    enableMouseTracking: false
                },
            },
            series: []
        }

        // 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);
            }
        });

        // Create the chart
        var chart = new Highcharts.Chart(options)
    });

    $.get('sample05-2.csv', function(data) {
        var options = {
            chart: {
                renderTo: 'container1',
                type: 'bar',
                zoomType: 'xy',
            },
            title: {
                text: 'test chart 2',
            },
            xAxis: {
                categories: []
            },
            yAxis: {
            },
            plotOptions: {
                bar: {
                    // 各データを値付きで表示する
                    dataLabels: {
                        enabled: true
                    },
                    // データ上にマウスポインタを置いた時に ToolTip が表示されないようにする
                    enableMouseTracking: false
                }
            },
            series: []
        }

        // 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)
    });
});
sample05-1.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.5
sample05-2.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
出力結果
sample05 (fc2 に置いてあるテストページに飛びます)

2013年1月26日土曜日

[Highcharts]2 つの csv ファイルからデータを読み込んで 1 つのグラフに表示

highcharts1.html
<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.5
highcharts1_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 に置いてあるテストページに飛びます)

2013年1月19日土曜日

[Highcharts]棒グラフと線グラフ同時に表示

sample03.js
$(document).ready(function() {
    var options = {
        chart: {
            renderTo: 'container0',
            zoomType: 'xy',
        },
        title: {
            text: 'test chart 0',
        },
        xAxis: {
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
        },
        yAxis: {
        },
        series: [
            {
                type: 'column',
                name: 'sample0',
                data: [3, 5, 8, 2, 6, 9],
            },
            {
                type: 'line',
                name: 'total',
                data: [3, 8, 16, 18, 24, 33],
            }
        ]
    }

    // Create the chart
    var chart = new Highcharts.Chart(options)
});
sample03.html
<html>
  <head>
    <title>Highcharts test</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="js/sample03.js">>/script>
  </head>
  <body>
    <div id="container0" style="height: 1200px; margin: 0;"></div>
  </body>
</html>
出力結果
sample03 (fc2 に置いてあるテストページに飛びます)

2013年1月14日月曜日

[Highcharts]csvファイルからデータを取り込んで表示するグラフ

ソースコード
<!DOCTYPE HTML>
<html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 <title>Highcharts example 02</title>
 <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">
 $(document).ready(function() {
 var options = {
   chart: {
     renderTo: 'container',
     defaultSeriesType: 'line',
   },
   title: {
     text: '月平均気温'
   },
   xAxis: {
     categories: []
   },
   yAxis: {
     title: {
       text: '気温 (℃)'
     },
     plotLines: [
       {
         value: 0,
         width: 2,
         color: 'red'
       }
     ]
   },
   series: []
 }

 $.get('sample02.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) {
     if (itemNo > 0) options.xAxis.categories.push(item);
   });
 }
 // the rest of the lines contain data with their name in the first position
 else {
   var series = {
   data: []
 };
 $.each(items, function(itemNo, item) {
   if (itemNo == 0) {
     series.name = item;
   }
   else {
     series.data.push(parseFloat(item));
   }
 });
 
 options.series.push(series);
 }
 });
 
 // Create the chart
 var chart = new Highcharts.Chart(options);
 });
 });
 </script>
 </head>
 <body>
 <div id="container" style="width: 600px; height: 400px; margin: 0 auto"></div>
 </body>
</html>
データファイル
Categories,Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec
Tokyo,5.1,7.0,8.1,14.5,18.5,22.8,27.3,27.5,25.1,19.5,14.9,7.5
Osaka,4.4,7.4,8.1,13.8,19.6,24.2,27.8,28.9,25.2,19.5,15.2,8.1
Sapporo,-3.8,-1.1,0.7,6.9,11.1,17.3,21.8,26.6,19.2,12.1,6,-2
Naha,14.9,17.6,17.1,20.4,23.9,27.9,28.9,28.3,27.9,25.2,23.7,18.6
出力結果
sample02 (fc2 に置いてあるテストページに飛びます)

[Highcharts]範囲を指定すると拡大するグラフ

chartでzoomTypeを指定する。
ソースコード
<!DOCTYPE HTML>
<html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 <title>Highcharts example 01</title>
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
 <script type="text/javascript">
 var chart;
 $(document).ready(function() {
 chart = new Highcharts.Chart({
 chart: {
   renderTo: 'container',
   zoomType: 'x',
 },
 title: {
   text: '月平均気温',
 },
 xAxis: {
   categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
                'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
 },
 yAxis: {
   title: {
     text: '気温 (℃)'
   },
   plotLines: [
     {
       value: 0,
       width: 2,
       color: 'red'
     }
   ]
 },
 series: [
   {
     name: 'Tokyo',
     data: [5.1,7.0,8.1,14.5,18.5,22.8,27.3,27.5,25.1,19.5,14.9,7.5],
   },
   {
     name: 'Osaka',
     data: [4.4,7.4,8.1,13.8,19.6,24.2,27.8,28.9,25.2,19.5,15.2,8.1]
   },
   {
     name: 'Sapporo',
     data: [-3.8,-1.1,0.7,6.9,11.1,17.3,21.8,26.6,19.2,12.1,6,-2]
   },
   {
     name: 'Naha',
     data: [14.9,17.6,17.1,20.4,23.9,27.9,28.9,28.3,27.9,25.2,23.7,18.6],
   }
 ]
 });
 });
 </script>
 </head>
 <body>
 <script type="text/javascript" src="js/highcharts.js"></script>
 <script type="text/javascript" src="js/modules/exporting.js"></script>
 <div id="container" style="width: 600px; height: 400px; margin: 0 auto"></div>
 </body>
</html>
出力結果
sample01 (fc2 に置いてあるテストページに飛びます)

[Highcharts]基本の折れ線グラフ

ソースコード
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Highcharts example 00</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type="text/javascript">
      var chart;
      $(document).ready(function() {
        chart = new Highcharts.Chart({
          chart: {
       renderTo: 'container',
           defaultSeriesType: 'line',
          },
          title: {
           text: '月平均気温',
          },
          xAxis: {
           categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
        'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
          },
          yAxis: {
         title: {
             text: '気温 (℃)'
            },
         plotLines: [
            {
             value: 0,
               width: 2,
               color: 'red'
             }
            ]
         },
          series: [
            {
               name: 'Tokyo',
               data: [5.1,7.0,8.1,14.5,18.5,22.8,27.3,27.5,25.1,19.5,14.9,7.5],
            },
            {
               name: 'Osaka',
               data: [4.4,7.4,8.1,13.8,19.6,24.2,27.8,28.9,25.2,19.5,15.2,8.1]
            },
            {
               name: 'Sapporo',
               data: [-3.8,-1.1,0.7,6.9,11.1,17.3,21.8,26.6,19.2,12.1,6,-2]
            },
            {
               name: 'Naha',
               data: [14.9,17.6,17.1,20.4,23.9,27.9,28.9,28.3,27.9,25.2,23.7,18.6],
            }
          ]
        });
      });
    </script>
  </head>
  <body>
    <script type="text/javascript" src="js/highcharts.js"></script>
    <script type="text/javascript" src="js/modules/exporting.js"></script>
    <div id="container" style="width: 600px; height: 400px; margin: 0 auto"></div>
  </body>
</html>
出力結果
sample00 (fc2 に置いてあるテストページに飛びます)

[Highcharts]インストール

Highcharts から ダウンロードする。