summaryrefslogtreecommitdiff
path: root/priv/static/metrics-graphics-3.0-alpha3/examples/charts/lines.htm
blob: b758d34254f7979ea002d65df422a424243f7d4a (plain) (blame)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
            <div class='row trunk-section'>
                <div class='col-lg-7 text-center' id='fake_users1'></div>
                <div class='col-lg-5'>
                    <div class='data-column'><a href='data/fake_users1.json'>data</a></div>

<pre><code class='javascript'>d3.json('data/fake_users1.json', function(data) {
    data = MG.convert.date(data, 'date');
    MG.data_graphic({
        title: "Line Chart",
        description: "This is a simple line chart. You can remove the area portion by adding <i>area: false</i> to the arguments list.",
        data: data,
        width: 600,
        height: 200,
        right: 40,
        target: document.getElementById('fake_users1'),
        x_accessor: 'date',
        y_accessor: 'value'
    });
});</code></pre>

                </div>
            </div>

            <div class='row trunk-section'>
                <div class='col-lg-7 text-center' id='confidence_band'></div>
                <div class='col-lg-5'>
                    <div class='data-column'><a href='data/confidence_band.json'>data</a></div>

<pre><code class='javascript'>d3.json('data/confidence_band.json', function(data) {
    data = MG.convert.date(data, 'date');
    MG.data_graphic({
        title: "Confidence Band",
        description: "This is an example of a graphic with a confidence band and extended x-axis ticks enabled.",
        data: data,
        format: 'percentage',
        width: 600,
        height: 200,
        right: 40,
        area: false,
        target: '#confidence_band',
        show_secondary_x_label: false,
        show_confidence_band: ['l', 'u'],
        x_extended_ticks: true
    });
});</code></pre>

                </div>
            </div>

            <div class='row trunk-section'>
                <div class='col-lg-7 text-center' id='small-range'></div>
                <div class='col-lg-5'>
                    <div class='data-column'><a href='data/small-range.json'>data</a></div>

<pre><code class='javascript'>d3.json('data/small-range.json', function(data) {
    data = MG.convert.date(data, 'date');
    MG.data_graphic({
        title: "Small Range of Integers",
        description: "When we have a data object of integers and a small range of values, the auto-generated set of y-axis ticks are filtered so that we don't include fractional values.",
        data: data,
        interpolate: d3.curveLinear,
        width: 600,
        height: 200,
        right: 40,
        target: '#small-range'
    });
});</code></pre>

                </div>
            </div>

            <div class='row trunk-section'>
                <div class='col-lg-7 text-center'>
                    <div id='briefing-1'></div>
                    <div id='briefing-2'></div>
                </div>
                <div class='col-lg-5'>
                    <div class='data-column'>
                        <a href='data/brief-1.json'>data 1</a>,
                        <a href='data/brief-2.json'>data 2</a>
                    </div>

<pre><code class='javascript'>d3.json('data/brief-1.json', function(data) {
    data = MG.convert.date(data, 'date');
    MG.data_graphic({
        title: "Linked Graphic",
        description: "The two graphics in this section are linked together. A rollover in one causes a rollover in the other.",
        data: data,
        linked: true,
        width: 600,
        height: 200,
        right: 40,
        xax_count: 4,
        target: '#briefing-1'
    });
});

d3.json('data/brief-2.json', function(data) {
    data = MG.convert.date(data, 'date');
    MG.data_graphic({
        title: "Other Linked Graphic",
        description: "Roll over and watch as the graphic to the left triggers.",
        data: data,
        area: false,
        linked: true,
        width: 600,
        height: 200,
        right: 40,
        xax_count: 4,
        target: '#briefing-2'
    });
});</code></pre>

                </div>
            </div>

            <div class='row trunk-section'>
                <div class='col-lg-7 text-center' id='singleton'></div>
                <div class='col-lg-5'>

<pre><code class='javascript'>MG.data_graphic({
    title: "Singleton",
    description: "Handling a solitary data point.",
    data: [{'date': new Date('2015-03-05T21:00:00Z'), 'value': 12000}],
    width: 600,
    height: 200,
    right: 40,
    target: '#singleton'
});</code></pre>

                </div>
            </div>

            <div class='row trunk-section'>
                <div class='col-lg-7 text-center' id='custom-color'></div>
                <div class='col-lg-5'>

<pre><code class='javascript'>d3.json('data/fake_users1.json', function(data) {
    data = MG.convert.date(data, 'date');
    MG.data_graphic({
        title: "Changing Single Line Color",
        description: "For single line charts, there are two simple ways to change a line color. The first is to change the css (described on the wiki). The other is to specify a color value using color: <em>string</em> or colors: <em>string</em>.",
        data: data,
        width: 600,
        height: 200,
        right: 40,
        color: '#8C001A',
        target: 'div#custom-color',
        x_accessor: 'date',
        y_accessor: 'value'
    });
});</code></pre>

                </div>
            </div>

            <div class='row trunk-section'>
                <div class='col-lg-7 text-center' id='area_flipped_users_gain_loss'></div>
                <div class='col-lg-5'>
                    <div class='data-column'><a href='data/fake_users1.json'>data</a></div>

                    <pre><code class='javascript'>d3.json('data/fake_users1.json', function(data) {

    var max = d3.max(data, function (d) {
        return d.value;
    });
    var min = d3.min(data, function(d) {
        return d.value;
    });

    var offsetForNegativeValues = ((max - min) / 1.75);

    for (var i = 0; i < data.length; i++) {
        data[i].value = (data[i].value - offsetForNegativeValues) / 1000000;
    }

    data = MG.convert.date(data, 'date');
    MG.data_graphic({
        title: "Flipped area under Y value baseline",
        description: "This is a line chart having a flipped area under a Y value baseline",
        data: data,
        width: 600,
        height: 200,
        right: 40,
        area: true,
        flip_area_under_y_value: 0,
        target: document.getElementById('area_flipped_users_gain_loss'),
        x_accessor: 'date',
        y_accessor: 'value'
    });
});</code></pre>

                </div>
            </div>

<script>



d3.json('data/fake_users1.json', function(data) {
    data = MG.convert.date(data, 'date');
    MG.data_graphic({
        title: "Changing Single Line Color",
        description: "For single line charts, there are two simple ways to change a line color. The first is to change the css (described on the wiki). The other is to specify a color value using color: <em>string</em> or colors: <em>string</em>.",
        data: data,
        width: 600,
        height: 200,
        right: 40,
        color: '#8C001A',
        target: 'div#custom-color',
        x_accessor: 'date',
        y_accessor: 'value'
    });
});

MG._hooks = {};
d3.json('data/fake_users1.json', function(data) {
    data = MG.convert.date(data, 'date');
    MG.data_graphic({
        title: "Line Chart",
        description: "This is a simple line chart. You can remove the area portion by adding <i>area: false</i> to the arguments list.",
        data: data,
        width: 600,
        height: 200,
        right: 40,
        target: document.getElementById('fake_users1'),
        x_accessor: 'date',
        y_accessor: 'value'
    });
});

d3.json('data/confidence_band.json', function(data) {
    data = MG.convert.date(data, 'date');
    MG.data_graphic({
        title: "Confidence Band",
        description: "This is an example of a graphic with a confidence band and extended x-axis ticks enabled.",
        data: data,
        format: 'percentage',
        width: 600,
        height: 200,
        right: 40,
        area: false,
        target: '#confidence_band',
        show_secondary_x_label: false,
        show_confidence_band: ['l', 'u'],
        x_extended_ticks: true
    });
});

d3.json('data/small-range.json', function(data) {
    data = MG.convert.date(data, 'date');
    MG.data_graphic({
        title: "Small Range of Integers",
        description: "When we have a data object of integers and a small range of values, the auto-generated set of y-axis ticks are filtered so that we don't include fractional values.",
        data: data,
        interpolate: d3.curveLinear,
        width: 600,
        height: 200,
        right: 40,
        target: '#small-range'
    });
});

d3.json('data/brief-1.json', function(data) {
    data = MG.convert.date(data, 'date');
    MG.data_graphic({
        title: "Linked Graphic",
        description: "The two graphics in this section are linked together. A rollover in one causes a rollover in the other.",
        data: data,
        linked: true,
        width: 600,
        height: 200,
        right: 40,
        xax_count: 4,
        target: '#briefing-1'
    });
});

d3.json('data/brief-2.json', function(data) {
    data = MG.convert.date(data, 'date');
    MG.data_graphic({
        title: "Other Linked Graphic",
        description: "Roll over and watch as the graphic to the left triggers.",
        data: data,
        area: false,
        linked: true,
        width: 600,
        height: 200,
        right: 40,
        xax_count: 4,
        target: '#briefing-2'
    });
});

MG.data_graphic({
    title: "Singleton",
    description: "Handling a solitary data point.",
    data: [{'date': new Date('2015-03-05T21:00:00Z'), 'value': 12000}],
    width: 600,
    height: 200,
    right: 40,
    target: '#singleton'
});

d3.json('data/fake_users1.json', function(data) {

    var max = d3.max(data, function (d) {
        return d.value;
    });
    var min = d3.min(data, function(d) {
        return d.value;
    });

    var offsetForNegativeValues = ((max - min) / 1.75);

    for (var i = 0; i < data.length; i++) {
        data[i].value = (data[i].value - offsetForNegativeValues) / 1000000;
    }

    data = MG.convert.date(data, 'date');
    MG.data_graphic({
        title: "Flipped area under Y value baseline",
        description: "This is a line chart having a flipped area under a Y value baseline",
        data: data,
        width: 600,
        height: 200,
        right: 40,
        area: true,
        flip_area_under_y_value: 0,
        target: document.getElementById('area_flipped_users_gain_loss'),
        x_accessor: 'date',
        y_accessor: 'value'
    });
});
</script>