-
Notifications
You must be signed in to change notification settings - Fork 13
/
nvd3-discrete-bar.html
143 lines (129 loc) · 2.87 KB
/
nvd3-discrete-bar.html
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
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="nvd3-behavior.html">
<!--
An element to create discrete bar chart using nvd3.
Example:
<nvd3-discrete-bar
data="[[data]]"
height="100"
width="400"
auto-resize>
</nvd3-discrete-bar>
Data Format:
```
[
{
key: "Cumulative Return",
values: [
{
"label" : "A" ,
"value" : -29.765957771107
} ,
{
"label" : "B" ,
"value" : 0
} ,
{
"label" : "C" ,
"value" : 32.807804682612
}
]
}
]
```
@group NVD3 Elements
@element nvd3-discrete-bar
@demo demo/nvd3-discrete-bar.html
@hero hero.svg
-->
<dom-module id="nvd3-discrete-bar">
<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-discrete-bar',
behaviors: [NVD3.ChartBehavior],
properties: {
/**
* NVD3 chart object.
*/
_chart: {
type: Object,
value: function() {
var that = this;
return nv.models.discreteBarChart()
.x(function(d) {
return d[that.xProp];
})
.y(function(d) {
return d[that.yProp];
});
}
},
/**
* Configurable x-axis property key
*/
xProp: {
type: String,
value: 'label'
},
/**
* Configurable y-axis property key
*/
yProp: {
type: String,
value: 'value'
},
/**
* NVD3 components which are used in this chart.
* It's required for binding events.
*/
_components: {
type: Array,
value: ['discretebar', 'legend', 'xAxis', 'yAxis', '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'
}
},
/**
* 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>