Skip to content

Commit 4b20835

Browse files
committed
turned the multiBarChart doc example into something that makes some sense
1 parent 7faa675 commit 4b20835

2 files changed

Lines changed: 29 additions & 37 deletions

File tree

9.82 KB
Loading

‎nvd3/multiBarChart.py‎

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,58 +19,50 @@ class multiBarChart(NVD3Chart):
1919
about the categories. Reading a multiple bar graph includes looking at extremes
2020
(tallest/longest vs. shortest) in each grouping.
2121
22-
.. image:: ../_static/screenshot/multiBarChart.png
22+
.. image:: ../_static/doc_images/multiBarChart.png
2323
2424
Python example::
2525
2626
from nvd3 import multiBarChart
27-
chart = multiBarChart(name='multiBarChart', height=400, width=400)
28-
xdata = [0, 1, 3, 4]
29-
ydata = [6, 12, 9, 16]
27+
chart = multiBarChart(width=500, height=400, x_axis_format=None)
28+
xdata = ['one', 'two', 'three', 'four']
29+
ydata1 = [6, 12, 9, 16]
30+
ydata2 = [8, 14, 7, 11]
3031
31-
extra_serie = {"tooltip": {"y_start": "", "y_end": " balls"}}
32-
chart.add_serie(name="Serie 1", y=ydata, x=xdata)
32+
chart.add_serie(name="Serie 1", y=ydata1, x=xdata)
33+
chart.add_serie(name="Serie 2", y=ydata2, x=xdata)
3334
chart.buildhtml()
3435
3536
Javascript generated::
3637
37-
data_MultiBarChart = [{ "key" : "Serie 1",
38-
"values" : [
39-
{ "x" : 0
40-
"y" : 6
41-
},
42-
{ "x" : 1,
43-
"y" : 12
44-
},
45-
{ "x" : 3,
46-
"y" : 9
47-
},
48-
],
49-
"yAxis" : "1"
50-
}]
51-
5238
nv.addGraph(function() {
5339
var chart = nv.models.multiBarChart();
54-
chart.xAxis
55-
.tickFormat(d3.format(',.2f'));
5640
chart.yAxis
5741
.tickFormat(d3.format(',.2f'));
58-
chart.tooltipContent(function(key, y, e, graph) {
59-
var x = String(graph.point.x);
60-
var y = String(graph.point.y);
61-
if(key == 'Serie 1'){
62-
var y = String(graph.point.y) + ' balls';
63-
}
64-
tooltip_str = '<center><b>'+key+'</b></center>' + y + ' at ' + x;
65-
return tooltip_str;
66-
});
67-
d3.select('#MultiBarChart svg')
68-
.datum(data_MultiBarChart)
69-
.transition()
70-
.duration(500)
42+
chart.xAxis
43+
chart.showLegend(true);
44+
d3.select('#multiBarChart svg')
45+
.datum(data_multiBarChart)
46+
.transition().duration(500)
47+
.attr('width', 500)
48+
.attr('height', 400)
7149
.call(chart);
72-
return chart;
50+
51+
return chart;
7352
});
53+
data_multiBarChart=[
54+
{"yAxis": "1",
55+
"values": [{"x": "one", "y": 6},
56+
{"x": "two", "y": 12},
57+
{"x": "three", "y": 9},
58+
{"x": "four", "y": 16}],
59+
"key": "Serie 1"},
60+
{"yAxis": "1",
61+
"values": [{"x": "one", "y": 8},
62+
{"x": "two", "y": 14},
63+
{"x": "three", "y": 7},
64+
{"x": "four", "y": 11}],
65+
"key": "Serie 2"}];
7466
"""
7567
def __init__(self, **kwargs):
7668
NVD3Chart.__init__(self, **kwargs)

0 commit comments

Comments
 (0)