Adding a Custom Chart Color Palette

GravityCharts already comes with 26 color palettes available for you to choose from:

Screenshot showing existing color palettes

...however, if none of these existing palettes work with the design of your website you can add a new custom one with some custom coding:

add_filter( 'gk/gravitycharts/color-palettes', function ( $palettes ) {
    $palettes['custom_palette'] = [
        'label'           => 'Custom Palette',
        'borderColor'     => [
            'blue',
            'yellow',
            'aqua',
	    'red', 
	    'orange',
	    'green',
            'black'
        ],
        'backgroundColor' => [
            'blue',
            'yellow',
            'aqua',
	    'red', 
	    'orange',
	    'green',
            'black'
        ]
    ];
 
    return $palettes;
} );

The code above adds one new color palette with seven choices (one for each choice of your form field). You can add more colors or remove some if necessary.

Here's what our new color palette looks like on the Chart configuration feed:

Screenshot of the new color palette inside the Chart configuration feed

Learn here how to add this code snippet to your website: Where to put code samples

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us