1
|
function getBarChartDef() {
|
2
|
// regular stuff:
|
3
|
var chartDef = {};
|
4
|
chartDef.titleColor = "#222222";
|
5
|
chartDef.titleSize = 18;
|
6
|
chartDef.background = {type: 'gradient', angle: 90, colors: [['#CCCCCC', 0], ['#FFFFFF', 100]]};
|
7
|
chartDef.width = 600;
|
8
|
chartDef.height = 501;
|
9
|
chartDef.areaFill = {type: 'gradient', angle: 0, colors: [['#CCCCCC', 0], ['#FFFFFF', 100]]};
|
10
|
// chartDef.legendPosition = "right";
|
11
|
// chartDef.legendMargins = {horizontal: 10, vertical: 2};
|
12
|
// chartDef.margins = {top: 10, left: 10, right: 10, bottom: 10};
|
13
|
// chartDef.grid = {xAxisStepSize: 10, yAxisStepSize: 10, lengthOfLineSegment: 3, lengthOfBlankSegment:2, xOffset: 5, yOffset: 5};
|
14
|
chartDef.title = "Stacked bar example:";
|
15
|
chartDef.threeD = true;
|
16
|
chartDef.horizontal = true;
|
17
|
chartDef.barWidth = 20;
|
18
|
chartDef.shadow = false;
|
19
|
// chartDef.spaceBetweenGroupsOfBars = 15;
|
20
|
// chartDef.spaceWithinGroupsOfBars = 3;
|
21
|
chartDef.transparency = opacity;
|
22
|
// chartDef.rangeMarkers = {orientation: 'h', color: '#00CCFF55', startPoint: 80, endPoint: 120};
|
23
|
chartDef.markers = [{shape: 'arrow', size: 10, color: '#FF0000', x: 40, y: 50},
|
24
|
{text: 'Bad year!', size: 12, x: 1, y: 40}];
|
25
|
|
26
|
// here starts the interesting thing:
|
27
|
|
28
|
// set as stacked:
|
29
|
// chartDef.stacked = true;
|
30
|
|
31
|
// set the values:
|
32
|
var data1 = {data: [45,32,22,44,10], colors: ['#BB5555', '#DD3333', '#FF0000','#3333DD','#5555BB']};
|
33
|
// var data2 = {data: [58,24,76], color: ['#00FFFF', '#FFFF00', '#00FF00'], legend: 'Stuff'};
|
34
|
// var data3 = {data: [77,100,55], color: ['#5555BB', '#3333DD', '#0000FF'], legend: 'Rules!'};
|
35
|
chartDef.bars = [data1]; //, data2, data3];
|
36
|
|
37
|
// the sum of each bars by series will give (45+58+77=180, 32+24+100=156, 22+76+55=153)
|
38
|
// we give the chart a max value of 200 to let it breathe ;)
|
39
|
chartDef.maxValue = 60;
|
40
|
|
41
|
// a simple x axis with 3 values (note the scaling):
|
42
|
chartDef.yAxis = {
|
43
|
labels: ['2008', '2009', '2010','2011','2012'],
|
44
|
positions: [6, 15, 25, 35, 45], // required for Google position (numbers must match how many labels you have) of label with marker attached
|
45
|
style: {textColor: '#000000', fontSize: 12, alignment: 'right', drawTickMarks: true},
|
46
|
minRange: 0, maxRange: 50
|
47
|
};
|
48
|
|
49
|
// and the y axis: the positions are scaled in a range of 0-100 anyway, so you can use [0,10...] or [0,20...] indiferently:
|
50
|
chartDef.xAxis = {
|
51
|
labels: ['0','10','20','30','40','50','60'],
|
52
|
positions: [0, 10, 20, 30, 40, 50, 60],
|
53
|
style: {textColor: '#000000', fontSize: 12, alignment: 'right', tickMarkLength: 12, tickMarkColor: '#FF0022'},
|
54
|
minRange: 0, maxRange: 60
|
55
|
};
|
56
|
|
57
|
return chartDef;
|
58
|
}
|
59
|
|