Custom colors for Pie Chart

This commit is contained in:
Mel O'Hagan 2022-08-11 16:59:50 +01:00
parent 7c13d3ded9
commit 352d236f2e
2 changed files with 74 additions and 4 deletions

View File

@ -1811,10 +1811,11 @@
}, },
{ {
"type": "select", "type": "select",
"label": "Colours", "label": "Colors",
"key": "palette", "key": "palette",
"defaultValue": "Palette 1", "defaultValue": "Palette 1",
"options": [ "options": [
"Custom",
"Palette 1", "Palette 1",
"Palette 2", "Palette 2",
"Palette 3", "Palette 3",
@ -1827,6 +1828,56 @@
"Palette 10" "Palette 10"
] ]
}, },
{
"type": "color",
"label": "C1",
"key": "c1",
"barSeparator": false,
"dependsOn": {
"setting": "palette",
"value": "Custom"
}
},
{
"type": "color",
"label": "C2",
"key": "c2",
"barSeparator": false,
"dependsOn": {
"setting": "palette",
"value": "Custom"
}
},
{
"type": "color",
"label": "C3",
"key": "c3",
"barSeparator": false,
"dependsOn": {
"setting": "palette",
"value": "Custom"
}
},
{
"type": "color",
"label": "C4",
"key": "c4",
"barSeparator": false,
"dependsOn": {
"setting": "palette",
"value": "Custom"
}
},
{
"type": "color",
"label": "C5",
"key": "c5",
"barSeparator": false,
"dependsOn": {
"setting": "palette",
"value": "Custom"
}
},
{ {
"type": "boolean", "type": "boolean",
"label": "Data Labels", "label": "Data Labels",
@ -1893,10 +1944,11 @@
}, },
{ {
"type": "select", "type": "select",
"label": "Colours", "label": "Colors",
"key": "palette", "key": "palette",
"defaultValue": "Palette 1", "defaultValue": "Palette 1",
"options": [ "options": [
"Custom",
"Palette 1", "Palette 1",
"Palette 2", "Palette 2",
"Palette 3", "Palette 3",
@ -1909,6 +1961,16 @@
"Palette 10" "Palette 10"
] ]
}, },
{
"type": "color",
"label": "Color",
"key": "color",
"barSeparator": false,
"dependsOn": {
"setting": "palette",
"value": "Custom"
}
},
{ {
"type": "boolean", "type": "boolean",
"label": "Data Labels", "label": "Data Labels",

View File

@ -13,6 +13,7 @@
export let legend export let legend
export let donut export let donut
export let palette export let palette
export let c1, c2, c3, c4, c5
$: options = setUpChart( $: options = setUpChart(
title, title,
@ -25,9 +26,13 @@
animate, animate,
legend, legend,
donut, donut,
palette palette,
c1 && c2 && c3 && c4 && c5 ? [c1, c2, c3, c4, c5] : null,
customColor
) )
$: customColor = palette === "Custom"
const setUpChart = ( const setUpChart = (
title, title,
dataProvider, dataProvider,
@ -39,7 +44,9 @@
animate, animate,
legend, legend,
donut, donut,
palette palette,
colors,
customColor
) => { ) => {
if ( if (
!dataProvider || !dataProvider ||
@ -70,6 +77,7 @@
.legend(legend) .legend(legend)
.legendPosition("right") .legendPosition("right")
.palette(palette) .palette(palette)
.colors(customColor ? colors : null)
// Add data if valid datasource // Add data if valid datasource
const series = data.map(row => parseFloat(row[valueColumn])) const series = data.map(row => parseFloat(row[valueColumn]))