diff --git a/src/core/core.config.js b/src/core/core.config.js index 6e83d5de327..aa76df7902b 100644 --- a/src/core/core.config.js +++ b/src/core/core.config.js @@ -132,6 +132,11 @@ function initConfig(config) { initOptions(config); + if (config.options.indexAxis === 'y' && config.data.labels.length === 0) { + config.data.labels = Object.keys(config.data.datasets[0].data); + config.data.datasets[0].data = Object.values(config.data.datasets[0].data); + } + return config; } diff --git a/test/fixtures/controller.bar/bar-indexAxis-y.js b/test/fixtures/controller.bar/bar-indexAxis-y.js new file mode 100644 index 00000000000..5bc55376cac --- /dev/null +++ b/test/fixtures/controller.bar/bar-indexAxis-y.js @@ -0,0 +1,20 @@ +module.exports = { + config: { + type: 'bar', + data: { + datasets: [{ + label: '# of Votes', + data: {a: 1, b: 3, c: 2} + }] + }, + options: { + indexAxis: 'y' + } + }, + options: { + canvas: { + height: 256, + width: 512 + } + } +}; diff --git a/test/fixtures/controller.bar/bar-indexAxis-y.png b/test/fixtures/controller.bar/bar-indexAxis-y.png new file mode 100644 index 00000000000..c8f71b48786 Binary files /dev/null and b/test/fixtures/controller.bar/bar-indexAxis-y.png differ diff --git a/test/specs/controller.bar.tests.js b/test/specs/controller.bar.tests.js index 53a4738477c..d0a3d413476 100644 --- a/test/specs/controller.bar.tests.js +++ b/test/specs/controller.bar.tests.js @@ -1721,4 +1721,23 @@ describe('Chart.controllers.bar', function() { after: [] }]); }); + + it('should treat and render indexAxis y as indexAxis x can without setting data labels', function() { + const chart = window.acquireChart({ + type: 'bar', + data: { + datasets: [ + { + label: '# of Votes', + data: {a: 1, b: 3, c: 2}, + }, + ], + }, + options: { + indexAxis: 'y', + }, + }); + + expect(chart.data.labels.length).toBe(3); + }); });