Skip to content

Commit 5ec4670

Browse files
committed
Merge pull request #1454 from jongmoon/master
Clamp YScale on MultiBarHorizontalChart
2 parents 7d5a847 + 3cd7ac4 commit 5ec4670

2 files changed

Lines changed: 42 additions & 10 deletions

File tree

src/models/multiBarHorizontalChart.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ nv.models.multiBarHorizontalChart = function() {
133133

134134
// Setup Scales
135135
x = multibar.xScale();
136-
y = multibar.yScale();
136+
y = multibar.yScale().clamp(true);
137137

138138
// Setup containers and skeleton of chart
139139
var wrap = container.selectAll('g.nv-wrap.nv-multiBarHorizontalChart').data([data]);

test/multiBarHorizontalChart.html

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<meta charset="utf-8">
33

4-
<link href="../src/nv.d3.css" rel="stylesheet" type="text/css">
4+
<link href="../build/nv.d3.css" rel="stylesheet" type="text/css">
55

66
<style>
77

@@ -13,7 +13,7 @@
1313
font: 12px sans-serif;
1414
}
1515

16-
#chart1 {
16+
.chart {
1717
margin: 10px;
1818
min-width: 100px;
1919
min-height: 100px;
@@ -31,12 +31,17 @@
3131
</style>
3232
<body>
3333

34-
<div id="chart1" class='with-3d-shadow with-transitions'>
34+
<div id="chart1" class='chart with-3d-shadow with-transitions'>
3535
<svg></svg>
3636
</div>
3737

38-
<script src="../lib/d3.v3.js"></script>
39-
<script src="../nv.d3.js"></script>
38+
<div id="chart2" class='chart'>
39+
Chart with forceY([10])
40+
<svg></svg>
41+
</div>
42+
43+
<script src="../bower_components/d3/d3.js"></script>
44+
<script src="../build/nv.d3.js"></script>
4045
<script src="../src/utils.js"></script>
4146
<script src="../src/tooltip.js"></script>
4247
<script src="../src/models/legend.js"></script>
@@ -349,17 +354,14 @@
349354
}
350355
];
351356

352-
var chart;
353-
354357
nv.addGraph(function() {
355-
chart = nv.models.multiBarHorizontalChart()
358+
var chart = nv.models.multiBarHorizontalChart()
356359
.x(function(d) { return d.label })
357360
.y(function(d) { return d.value })
358361
.margin({top: 30, right: 20, bottom: 50, left: 175})
359362
//.showValues(true)
360363
//.tooltips(false)
361364
.barColor(d3.scale.category20().range())
362-
.transitionDuration(250)
363365
.stacked(true)
364366
//.showControls(false);
365367

@@ -377,6 +379,36 @@
377379
return chart;
378380
});
379381

382+
var forceY_test_data = [
383+
{
384+
"key": "Series 1",
385+
"color": "#d67777",
386+
"values": [
387+
{"label": "Group A", "value": 10},
388+
{"label": "Group B", "value": 20},
389+
{"label": "Group C", "value": 30}
390+
]
391+
}
392+
];
393+
394+
nv.addGraph(function() {
395+
var chart = nv.models.multiBarHorizontalChart()
396+
.x(function(d) { return d.label })
397+
.y(function(d) { return d.value })
398+
.forceY([10])// To make 10 to be starting point.
399+
.margin({top: 30, right: 20, bottom: 50, left: 175})
400+
.showValues(true) //Show bar value next to each bar.
401+
.showControls(true); //Allow user to switch between "Grouped" and "Stacked" mode.
402+
chart.yAxis
403+
.tickFormat(d3.format(',.2f'));
404+
//chart.yScale().clamp(true);
405+
d3.select('#chart2 svg')
406+
.datum(forceY_test_data)
407+
.call(chart);
408+
409+
nv.utils.windowResize(chart.update);
380410

411+
return chart;
412+
});
381413

382414
</script>

0 commit comments

Comments
 (0)