Problem/Motivation
The chart is used in a block via the Chart type field. The "Background color" input of the chart may have an optional value. If I add one (f.e. #123456). It is stored well. I can edit it when I reopen the Edit block form. However, this background does not apply anywhere. Neither nor its parent contains this data.
Steps to reproduce
Drupal 11.3.11 | PHP 8.4 | No patches related to this module have been applied.
1. Add a Chart type field to an entity (f.e. block content).
2. Fill in a new chart with some values, and then set a bg color in the "Background color" input of the chart.
3. Save changes and see your entity (block) render.
4. Find the chart you added. It has no background applied.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | Screenshot_20260710-061131.png | 229.33 KB | andileco |
| charts-bg-color.png | 32.57 KB | serhii-che |
Issue fork charts-3609779
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
andileco commentedThank for reporting. I have a hunch this is library-specific. Which library are you using?
Comment #3
serhii-che commentedI use the Chart.js library
Comment #4
andileco commentedThank you. I can replicate with Chart.js, C3.js, Billboard.js, and (separate module) Apache Echarts.
Comment #5
andileco commented@serhii-che - are you providing a MR?
Comment #6
serhii-che commentedUnfortunately, I won't be able to fix this and create an MP due to my lack of skills in this area
Comment #7
andileco commentedIt looks like for Chart.js, the standard solution is CSS. You can also write a plugin, but I am not especially inclined to go this route. Will CSS work for you?
Comment #8
serhii-che commentedI've now added an option to apply a background, so that workaround works.
I just wanted to find out what exactly the problem was—whether it was with the 'charts' module or an incompatibility between the option and the Chart.js library. Thank you for your quick response and advice
Comment #9
andileco commentedI think this is pretty achievable to code by putting something like this in the library classes for each of the libraries that don't support it natively:
Comment #11
andileco commentedMoved forward with the approach described in #9 for Chart.js, Billboard.js, and C3.js.
I also added an additional:
For Billboard.js and C3.js. Chart.js already had it.
Comment #12
nikathoneCould we move the work that apply the background into a trait to avoid code duplication and improve maintainability?
Comment #13
andileco commented