diff --git a/samples/charts/bar/float.html b/samples/charts/bar/float.html
new file mode 100644
index 000000000..968deb9f2
--- /dev/null
+++ b/samples/charts/bar/float.html
@@ -0,0 +1,143 @@
+
+
+
+
+ Bar Chart
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/charts/bar/vertical.html b/samples/charts/bar/vertical.html
index ed69a4367..1cc2fd3e4 100644
--- a/samples/charts/bar/vertical.html
+++ b/samples/charts/bar/vertical.html
@@ -116,7 +116,6 @@
barChartData.labels.push(month);
for (var index = 0; index < barChartData.datasets.length; ++index) {
- // window.myBar.addData(randomScalingFactor(), index);
barChartData.datasets[index].data.push(randomScalingFactor());
}
diff --git a/samples/samples.js b/samples/samples.js
index 6e06756b2..15ece3ff5 100644
--- a/samples/samples.js
+++ b/samples/samples.js
@@ -19,6 +19,9 @@
}, {
title: 'Stacked groups',
path: 'charts/bar/stacked-group.html'
+ }, {
+ title: 'Floating',
+ path: 'charts/bar/float.html'
}]
}, {
title: 'Line charts',
diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js
index 7c30a6a43..212ff840e 100644
--- a/src/controllers/controller.bar.js
+++ b/src/controllers/controller.bar.js
@@ -213,6 +213,32 @@ module.exports = DatasetController.extend({
return parseArrayOrPrimitive.apply(this, arguments);
},
+ /**
+ * Overriding object data parsing since we support mixed primitive/array
+ * value-scale data for float bars
+ * @private
+ */
+ _parseObjectData: function(meta, data, start, count) {
+ var iScale = this._getIndexScale();
+ var vScale = this._getValueScale();
+ var vProp = vScale._getAxis();
+ var parsed = [];
+ var i, ilen, item, obj, value;
+ for (i = start, ilen = start + count; i < ilen; ++i) {
+ obj = data[i];
+ item = {};
+ item[iScale.id] = iScale._parseObject(obj, iScale._getAxis(), i);
+ value = obj[vProp];
+ if (helpers.isArray(value)) {
+ parseFloatBar(value, item, vScale, i);
+ } else {
+ item[vScale.id] = vScale._parseObject(obj, vProp, i);
+ }
+ parsed.push(item);
+ }
+ return parsed;
+ },
+
initialize: function() {
var me = this;
var meta;
diff --git a/src/core/core.scale.js b/src/core/core.scale.js
index 89d8d1c85..a06438eba 100644
--- a/src/core/core.scale.js
+++ b/src/core/core.scale.js
@@ -1391,8 +1391,8 @@ class Scale extends Element {
/**
* @private
*/
- _getAxisID() {
- return this.isHorizontal() ? 'xAxisID' : 'yAxisID';
+ _getAxis() {
+ return this.isHorizontal() ? 'x' : 'y';
}
/**
@@ -1403,7 +1403,7 @@ class Scale extends Element {
_getMatchingVisibleMetas(type) {
var me = this;
var metas = me.chart._getSortedVisibleDatasetMetas();
- var axisID = me._getAxisID();
+ var axisID = me._getAxis() + 'AxisID';
var result = [];
var i, ilen, meta;
diff --git a/test/fixtures/controller.bar/floatBar/data-as-objects-horizontal.js b/test/fixtures/controller.bar/floatBar/data-as-objects-horizontal.js
new file mode 100644
index 000000000..14dbb58d7
--- /dev/null
+++ b/test/fixtures/controller.bar/floatBar/data-as-objects-horizontal.js
@@ -0,0 +1,32 @@
+module.exports = {
+ config: {
+ type: 'horizontalBar',
+ data: {
+ labels: ['a', 'b', 'c'],
+ datasets: [
+ {
+ data: [{y: 'b', x: [2, 8]}, {y: 'c', x: [2, 5]}],
+ backgroundColor: '#ff0000'
+ },
+ {
+ data: [{y: 'a', x: 10}, {y: 'c', x: [6, 10]}],
+ backgroundColor: '#00ff00'
+ }
+ ]
+ },
+ options: {
+ legend: false,
+ title: false,
+ scales: {
+ xAxes: [{display: false, ticks: {min: 0}}],
+ yAxes: [{display: false, stacked: true}]
+ }
+ }
+ },
+ options: {
+ canvas: {
+ height: 256,
+ width: 512
+ }
+ }
+};
diff --git a/test/fixtures/controller.bar/floatBar/data-as-objects-horizontal.png b/test/fixtures/controller.bar/floatBar/data-as-objects-horizontal.png
new file mode 100644
index 000000000..39b4496f5
Binary files /dev/null and b/test/fixtures/controller.bar/floatBar/data-as-objects-horizontal.png differ
diff --git a/test/fixtures/controller.bar/floatBar/data-as-objects.js b/test/fixtures/controller.bar/floatBar/data-as-objects.js
new file mode 100644
index 000000000..08ab0a962
--- /dev/null
+++ b/test/fixtures/controller.bar/floatBar/data-as-objects.js
@@ -0,0 +1,32 @@
+module.exports = {
+ config: {
+ type: 'bar',
+ data: {
+ labels: ['a', 'b', 'c'],
+ datasets: [
+ {
+ data: [{x: 'b', y: [2, 8]}, {x: 'c', y: [2, 5]}],
+ backgroundColor: '#ff0000'
+ },
+ {
+ data: [{x: 'a', y: 10}, {x: 'c', y: [6, 10]}],
+ backgroundColor: '#00ff00'
+ }
+ ]
+ },
+ options: {
+ legend: false,
+ title: false,
+ scales: {
+ xAxes: [{display: false, stacked: true}],
+ yAxes: [{display: false, ticks: {min: 0}}]
+ }
+ }
+ },
+ options: {
+ canvas: {
+ height: 256,
+ width: 512
+ }
+ }
+};
diff --git a/test/fixtures/controller.bar/floatBar/data-as-objects.png b/test/fixtures/controller.bar/floatBar/data-as-objects.png
new file mode 100644
index 000000000..70c0adaba
Binary files /dev/null and b/test/fixtures/controller.bar/floatBar/data-as-objects.png differ