Default pie chart colors not customizable

Created on 28 January 2023, almost 2 years ago
Updated 19 April 2023, over 1 year ago

Problem/Motivation

When you make a pie chart you can not change the default colors for the chart itself. Can this be added to the next version of charts?

Proposed resolution

Add color fields to the graph proportions

✨ Feature request
Status

Fixed

Version

5.0

Component

Chart API

Created by

πŸ‡§πŸ‡ͺBelgium Khoebeke Brakel

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Khoebeke
  • πŸ‡§πŸ‡ͺBelgium Khoebeke Brakel
  • πŸ‡ΊπŸ‡ΈUnited States andileco

    Hi @Khoebeke - there are a few ways to do this currently but it depends a little on how you have your data set up and the library you are using (Highcharts is the best for this just because we've worked on this submodule the most). Can you share more details of your instance and approach?

  • πŸ‡§πŸ‡ͺBelgium Khoebeke Brakel

    Hi
    I use Highcharts.

    As fields I use 2 fields:

    • COUNT title field (used as data)
    • Content field (used as my labels)

    This way I get only options for 2 colors in my Charts fields, but I have more than 6 different labels, so the chart uses the default colors. I also want to make more charts on my website so just changing the default colors doesn't do it for me. I want to change the default colors per chart.

  • First commit to issue fork.
  • @nikathone opened merge request.
  • Status changed to Needs review over 1 year ago
  • πŸ‡¨πŸ‡¦Canada nikathone Ontario

    This initial code is to allow single axis chart type to take advantage of color selection method when grouped. I added a custom property on the chart_data element and updated the highcharts library to take advantage of this new property to set the color.

    It would be good to test this first using highcharts then I can go ahead and customize other libraries. If you want to test this using composer patch here is the path link: https://git.drupalcode.org/project/charts/-/merge_requests/53/diffs.patch

  • πŸ‡ΊπŸ‡ΈUnited States andileco

    I manually tested this successfully (see attachments), and the automated tests complete successfully too. The code is relatively minimal. I think this is a good solution. This will need to be applied to the other charting libraries, but for now, I'm happy to commit.

  • πŸ‡ΊπŸ‡ΈUnited States andileco
  • Status changed to Fixed over 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024