-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgridstack-highcharts.js
110 lines (101 loc) · 2.18 KB
/
gridstack-highcharts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Highcharts won't automatically set its height and won't adjust
// its width, so we need to set height and call reflow.
function resizeChart(elem) {
var $elem = $(elem);
var $chart = $(elem).find('> div > div');
$chart.find('> div').height($elem.height());
Highcharts.charts[$chart.data('highchartsChart')].reflow();
}
// store some chart options for reusability
var chartOptions = {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
};
var chartPlotOptions = {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false
},
showInLegend: true
}
};
var chartTooltip = {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
};
function initializeChart() {
Highcharts.chart('container', {
chart: chartOptions,
title: {
text: 'House Health Care Bill Votes For'
},
tooltip: chartTooltip,
plotOptions: chartPlotOptions,
series: [{
name: 'Party',
colorByPoint: true,
data: [{
name: 'Republican',
y: 100,
color: '#FF0000'
}, {
name: 'Democrat',
y: 0,
sliced: true,
selected: true
}]
}]
});
}
function initializeChartTwo() {
Highcharts.chart('container2', {
chart: chartOptions,
title: {
text: 'House Health Care Bill Votes Against'
},
tooltip: chartTooltip,
plotOptions: chartPlotOptions,
series: [{
name: 'Party',
colorByPoint: true,
data: [{
name: 'Democrat',
y: 90.61,
color: '#0000FF'
}, {
name: 'Republican',
y: 9.39,
sliced: true,
selected: true,
color: '#FF0000'
}]
}]
});
}
$(function() {
$('#grid').gridstack({
resizable: {
handles: 'e, se, s, sw, w'
}
});
var grid = $('#grid').data('gridstack');
for (var i = 0; i < $('.chart-container').length; i++) {
// convert elements to gridstack widgets
grid.makeWidget($('.chart-container')[i]);
}
$('.grid-stack').on('gsresizestop', function(event, elem) {
// update chart width and height on resize
resizeChart(elem);
});
// Build the charts
initializeChart();
initializeChartTwo();
// set chart size on first load
var $elems = $('.chart-container');
for (var j = 0; j < $elems.length; j++) {
resizeChart($elems[j]);
}
});