chartService

 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
app.service("ChartArtist", function() {
// Function to draw bar chart using the calling directives scope and element
// Params
// - scope: scope of the calling directive (sfChart)
// - element: angular element of the calling directive
// - d3: D3.d3
// - nv: NVD3.nv
this.drawBarChart = function(scope, element, d3, nv) {
// Field name to use for values on y-axis
var field_name = scope.field + "_" + scope.type;
console.log('field_name is', field_name);
// Data representation of the aggregate data for the chart
var chartData = [{
key: "Cumulative Data",
values: scope.data.slice(0,scope.bar_count)
}];
console.log('values is', scope.data);
// nv function to add a graph
nv.addGraph(function() {
var count = 0;
var chart = nv.models.discreteBarChart()
.x(function(d,i) {
//console.log('Xd is', d);
return i
}) //Specify the data accessors.
.y(function(d) {
// Return raw value if field is "contract"
//console.log('Yd is', d);
if (scope.field === "volume") return d[field_name]/1000;
return d[field_name];
})
.staggerLabels(false) //Too many bars and not enough room? Try staggering labels.
.tooltips(false) //Don't show tooltips
.showValues(false) //...instead, show the bar value right on top of each bar.
.transitionDuration(350);
d3.select(element.find("svg")[0])
.datum(chartData)
.call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
}
});