Highcharts 積み上げグループ縦棒グラフ
以下の例では、積み上げグループ縦棒グラフをデモします。
前の章でHighchartsの基本設定構文をすでに理解しました。次に、他の設定を見てみましょう。plotOptions に stacking 属性を追加します:
設定
plotOptions:データポイントオプション
plotOptionsは、チャートのデータポイントに関連する属性を設定するために使用します。plotOptionsは、各種チャートタイプによって、その属性設定が若干異なります。
チャートのスタック設定では、plotOptions.area.stacking を "percent" に設定します。スタックを無効にするには null を使用します。
var plotOptions = {
column: {
stacking: 'normal',
dataLabels: {
enabled: true,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
style: {
textShadow: '0 0 3px black'
}
}
}
};
series データ系列項目の設定
積み上げグループ内の各対応するデータ系列項目を設定します。
series: [{
name: 'John',
data: [5, 3, 4, 7, 2],
stack: 'male'
}]
例
ファイル名:highcharts_column_rotated.htm
<html>
<head>
<meta charset="UTF-8" />
<title>Highcharts 教程 | サンプル(example.com)</title>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
</head>
<body>
<div id="container" style="width: 550px; height: 400px; margin: 0 auto"></div>
<script language="JavaScript">
$(document).ready(function() {
var chart = {
type: 'column'
};
var title = {
text: 'Total fruit consumption, grouped by gender'
};
var xAxis = {
categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
};
var yAxis ={
allowDecimals: false,
min: 0,
title: {
text: 'Number of fruits'
}
};
var plotOptions = {
column: {
stacking: 'normal'
}
};
var credits = {
enabled: false
};
var series= [{
name: 'John',
data: [5, 3, 4, 7, 2],
stack: 'male'
}, {
name: 'Joe',
data: [3, 4, 4, 2, 5],
stack: 'male'
}, {
name: 'Jane',
data: [2, 5, 6, 2, 1],
stack: 'female'
}, {
name: 'Janet',
data: [3, 0, 4, 4, 3],
stack: 'female'
}];
var json = {};
json.chart = chart;
json.title = title;
json.xAxis = xAxis;
json.yAxis = yAxis;
json.plotOptions = plotOptions;
json.credits = credits;
json.series = series;
$('#container').highcharts(json);
});
</script>
</body>
</html>
上記の例の出力結果は次のとおりです:
その他の拡張
Highcharts 縦棒グラフ