diff --git a/src/plugins/plugin.colors.ts b/src/plugins/plugin.colors.ts index b2817c85a..03af80eea 100644 --- a/src/plugins/plugin.colors.ts +++ b/src/plugins/plugin.colors.ts @@ -81,6 +81,12 @@ function containsColorsDefinitions( return false; } +function containsColorsDefinition( + descriptor: ColorsDescriptor +) { + return descriptor && (descriptor.borderColor || descriptor.backgroundColor); +} + export default { id: 'colors', @@ -95,11 +101,12 @@ export default { } const { - options: {elements}, - data: {datasets} + data: {datasets}, + options: chartOptions } = chart.config; + const {elements} = chartOptions; - if (!options.forceOverride && (containsColorsDefinitions(datasets) || elements && containsColorsDefinitions(elements))) { + if (!options.forceOverride && (containsColorsDefinitions(datasets) || containsColorsDefinition(chartOptions) || (elements && containsColorsDefinitions(elements)))) { return; } diff --git a/test/fixtures/plugin.colors/chart-options-colors.js b/test/fixtures/plugin.colors/chart-options-colors.js new file mode 100644 index 000000000..5add0c258 --- /dev/null +++ b/test/fixtures/plugin.colors/chart-options-colors.js @@ -0,0 +1,37 @@ +module.exports = { + config: { + type: 'bar', + data: { + labels: [0, 1, 2, 3, 4, 5], + datasets: [ + { + data: [0, 5, 10, null, -10, -5], + }, + { + data: [10, 2, 3, null, 10, 5] + } + ] + }, + options: { + backgroundColor: ['red', 'green'], + scales: { + x: { + ticks: { + display: false, + } + }, + y: { + ticks: { + display: false, + } + } + }, + plugins: { + legend: false, + colors: { + enabled: true + } + } + } + } +}; diff --git a/test/fixtures/plugin.colors/chart-options-colors.png b/test/fixtures/plugin.colors/chart-options-colors.png new file mode 100644 index 000000000..5b24310ed Binary files /dev/null and b/test/fixtures/plugin.colors/chart-options-colors.png differ