-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathnvd3-line.html
More file actions
211 lines (193 loc) · 4.16 KB
/
nvd3-line.html
File metadata and controls
211 lines (193 loc) · 4.16 KB
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
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="nvd3-behavior.html">
<!--
An element to create line chart using nvd3.
Example:
<nvd3-line
data="[[data]]"
height="100"
width="400"
auto-resize
show-legend
use-interactive-guideline>
</nvd3-line>
Data Format:
```
[
{
"key": "Sine Wave",
"color": "#ff7f0e",
"values": [{
"x": 0,
"y": 0
}, {
"x": 1,
"y": 0.09983341664682815
}, {
"x": 2,
"y": 0.19866933079506122
}, {
"x": 3,
"y": 0.29552020666133955
}, {
"x": 4,
"y": 0.3894183423086505
}, {
"x": 5,
"y": 0.479425538604203
}]
}, {
"key": "Cosine Wave",
"color": "#2ca02c",
"values": [{
"x": 0,
"y": 0.5
}, {
"x": 1,
"y": 0.49750208263901285
}, {
"x": 2,
"y": 0.4900332889206208
}, {
"x": 3,
"y": 0.477668244562803
}, {
"x": 4,
"y": 0.46053049700144255
}, {
"x": 5,
"y": 0.4387912809451864
}]
}
]
```
Custom X axis labels:
```
{
"0": "Label 0",
"1": "Label 1",
"2": "Label 2",
"3": "Label 3",
"4": "Label 4"
}
```
@group NVD3 Elements
@element nvd3-line
@demo demo/nvd3-line.html
@hero hero.svg
-->
<dom-module id="nvd3-line">
<template>
<style include="nvd3-shared-styles"></style>
<!-- We need to put svg tag inside a div to set correct margins -->
<div>
<svg id="svg"></svg>
</div>
</template>
<script>
Polymer({
is: 'nvd3-line',
behaviors: [NVD3.ChartBehavior],
properties: {
/**
* NVD3 chart object.
*/
_chart: {
type: Object,
value: function () {
return nv.models.lineChart();
}
},
/**
* Whether to display the legend or not
*/
showLegend: {
type: Boolean,
value: false
},
/**
* Sets the chart to use a guideline and floating tooltip instead of
* requiring the user to hover over specific hotspots.
*/
useInteractiveGuideline: {
type: Boolean,
value: false
},
/**
* Custom Labels for x axis.
* e.g. {
* "0": "Label 0",
* "1": "Label 1",
* "2": "Label 2",
* "3": "Label 3",
* "4": "Label 4"
* }
*/
xAxisLabels: {
type: Object,
value: {},
observer: '_xAxisLabelsChanged'
},
/**
* NVD3 components which are used in this chart.
* It's required for binding events.
*/
_components: {
type: Array,
value: ['lines', 'legend', 'focus', 'xAxis', 'x2Axis', 'yAxis', 'y2Axis', 'tooltip']
},
/**
* Display or hide the X axis
*/
showXAxis: {
type: Boolean,
value: true,
observer: '_showXAxis'
},
/**
* Display or hide the Y axis
*/
showYAxis: {
type: Boolean,
value: true,
observer: '_showYAxis'
}
},
/**
* Check if custom labels is set and update tickFormat of x axis.
*
* @private
*/
_xAxisLabelsChanged: function () {
var xAxisLabels = this.xAxisLabels;
this._chart.xAxis.tickFormat(function (d) {
if (xAxisLabels.hasOwnProperty(d)) {
return xAxisLabels[d];
} else {
return d;
}
});
},
/**
* Observer for showXAxis will change this option on the chart
* @private
* @param {Boolean} showXAxis
*/
_showXAxis: function (newValue) {
if (newValue !== undefined) {
this._chart.showXAxis(newValue);
}
},
/**
* Observer for showYAxis will change this option on the chart
* @private
* @param {Boolean} showYAxis
*/
_showYAxis: function (newValue) {
if (newValue !== undefined) {
this._chart.showYAxis(newValue);
}
}
});
</script>
</dom-module>