Subversion-Projekte lars-tiefland.cienc

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
9 lars 1
<!DOCTYPE HTML>
2
<html>
3
	<head>
4
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5
		<title>Highcharts Example</title>
6
 
7
		<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
8
		<style type="text/css">
9
${demo.css}
10
		</style>
11
		<script type="text/javascript">
12
$(function () {
13
    $.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=usdeur.json&callback=?', function (data) {
14
        var detailChart;
15
 
16
        $(document).ready(function () {
17
 
18
            // create the detail chart
19
            function createDetail(masterChart) {
20
 
21
                // prepare the detail chart
22
                var detailData = [],
23
                    detailStart = data[0][0];
24
 
25
                $.each(masterChart.series[0].data, function () {
26
                    if (this.x >= detailStart) {
27
                        detailData.push(this.y);
28
                    }
29
                });
30
 
31
                // create a detail chart referenced by a global variable
32
                detailChart = $('#detail-container').highcharts({
33
                    chart: {
34
                        marginBottom: 120,
35
                        reflow: false,
36
                        marginLeft: 50,
37
                        marginRight: 20,
38
                        style: {
39
                            position: 'absolute'
40
                        }
41
                    },
42
                    credits: {
43
                        enabled: false
44
                    },
45
                    title: {
46
                        text: 'Historical USD to EUR Exchange Rate'
47
                    },
48
                    subtitle: {
49
                        text: 'Select an area by dragging across the lower chart'
50
                    },
51
                    xAxis: {
52
                        type: 'datetime'
53
                    },
54
                    yAxis: {
55
                        title: {
56
                            text: null
57
                        },
58
                        maxZoom: 0.1
59
                    },
60
                    tooltip: {
61
                        formatter: function () {
62
                            var point = this.points[0];
63
                            return '<b>' + point.series.name + '</b><br/>' + Highcharts.dateFormat('%A %B %e %Y', this.x) + ':<br/>' +
64
                                '1 USD = ' + Highcharts.numberFormat(point.y, 2) + ' EUR';
65
                        },
66
                        shared: true
67
                    },
68
                    legend: {
69
                        enabled: false
70
                    },
71
                    plotOptions: {
72
                        series: {
73
                            marker: {
74
                                enabled: false,
75
                                states: {
76
                                    hover: {
77
                                        enabled: true,
78
                                        radius: 3
79
                                    }
80
                                }
81
                            }
82
                        }
83
                    },
84
                    series: [{
85
                        name: 'USD to EUR',
86
                        pointStart: detailStart,
87
                        pointInterval: 24 * 3600 * 1000,
88
                        data: detailData
89
                    }],
90
 
91
                    exporting: {
92
                        enabled: false
93
                    }
94
 
95
                }).highcharts(); // return chart
96
            }
97
 
98
            // create the master chart
99
            function createMaster() {
100
                $('#master-container').highcharts({
101
                    chart: {
102
                        reflow: false,
103
                        borderWidth: 0,
104
                        backgroundColor: null,
105
                        marginLeft: 50,
106
                        marginRight: 20,
107
                        zoomType: 'x',
108
                        events: {
109
 
110
                            // listen to the selection event on the master chart to update the
111
                            // extremes of the detail chart
112
                            selection: function (event) {
113
                                var extremesObject = event.xAxis[0],
114
                                    min = extremesObject.min,
115
                                    max = extremesObject.max,
116
                                    detailData = [],
117
                                    xAxis = this.xAxis[0];
118
 
119
                                // reverse engineer the last part of the data
120
                                $.each(this.series[0].data, function () {
121
                                    if (this.x > min && this.x < max) {
122
                                        detailData.push([this.x, this.y]);
123
                                    }
124
                                });
125
 
126
                                // move the plot bands to reflect the new detail span
127
                                xAxis.removePlotBand('mask-before');
128
                                xAxis.addPlotBand({
129
                                    id: 'mask-before',
130
                                    from: data[0][0],
131
                                    to: min,
132
                                    color: 'rgba(0, 0, 0, 0.2)'
133
                                });
134
 
135
                                xAxis.removePlotBand('mask-after');
136
                                xAxis.addPlotBand({
137
                                    id: 'mask-after',
138
                                    from: max,
139
                                    to: data[data.length - 1][0],
140
                                    color: 'rgba(0, 0, 0, 0.2)'
141
                                });
142
 
143
 
144
                                detailChart.series[0].setData(detailData);
145
 
146
                                return false;
147
                            }
148
                        }
149
                    },
150
                    title: {
151
                        text: null
152
                    },
153
                    xAxis: {
154
                        type: 'datetime',
155
                        showLastTickLabel: true,
156
                        maxZoom: 14 * 24 * 3600000, // fourteen days
157
                        plotBands: [{
158
                            id: 'mask-before',
159
                            from: data[0][0],
160
                            to: data[data.length - 1][0],
161
                            color: 'rgba(0, 0, 0, 0.2)'
162
                        }],
163
                        title: {
164
                            text: null
165
                        }
166
                    },
167
                    yAxis: {
168
                        gridLineWidth: 0,
169
                        labels: {
170
                            enabled: false
171
                        },
172
                        title: {
173
                            text: null
174
                        },
175
                        min: 0.6,
176
                        showFirstLabel: false
177
                    },
178
                    tooltip: {
179
                        formatter: function () {
180
                            return false;
181
                        }
182
                    },
183
                    legend: {
184
                        enabled: false
185
                    },
186
                    credits: {
187
                        enabled: false
188
                    },
189
                    plotOptions: {
190
                        series: {
191
                            fillColor: {
192
                                linearGradient: [0, 0, 0, 70],
193
                                stops: [
194
                                    [0, Highcharts.getOptions().colors[0]],
195
                                    [1, 'rgba(255,255,255,0)']
196
                                ]
197
                            },
198
                            lineWidth: 1,
199
                            marker: {
200
                                enabled: false
201
                            },
202
                            shadow: false,
203
                            states: {
204
                                hover: {
205
                                    lineWidth: 1
206
                                }
207
                            },
208
                            enableMouseTracking: false
209
                        }
210
                    },
211
 
212
                    series: [{
213
                        type: 'area',
214
                        name: 'USD to EUR',
215
                        pointInterval: 24 * 3600 * 1000,
216
                        pointStart: data[0][0],
217
                        data: data
218
                    }],
219
 
220
                    exporting: {
221
                        enabled: false
222
                    }
223
 
224
                }, function (masterChart) {
225
                    createDetail(masterChart);
226
                })
227
                    .highcharts(); // return chart instance
228
            }
229
 
230
            // make the container smaller and add a second container for the master chart
231
            var $container = $('#container')
232
                .css('position', 'relative');
233
 
234
            $('<div id="detail-container">')
235
                .appendTo($container);
236
 
237
            $('<div id="master-container">')
238
                .css({
239
                    position: 'absolute',
240
                    top: 300,
241
                    height: 100,
242
                    width: '100%'
243
                })
244
                    .appendTo($container);
245
 
246
            // create master and in its callback, create the detail chart
247
            createMaster();
248
        });
249
    });
250
});
251
		</script>
252
	</head>
253
	<body>
254
<script src="../../js/highcharts.js"></script>
255
<script src="../../js/modules/exporting.js"></script>
256
 
257
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
258
 
259
	</body>
260
</html>