Skip to content

fix: color array support in charts #1250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

edgant
Copy link

@edgant edgant commented Apr 30, 2025

Fix broken support for color arrays introduced in

@lukasvinclav
Copy link
Contributor

Do we have an issue where I can read more about this issue? On the demo site, I can change chart colors without any issues.

@edgant
Copy link
Author

edgant commented May 20, 2025

This is useful to to continue supporting when colors are passed as an array of strings instead of string to a chart component:

def dashboard_callback(request, context):
    context.update(
        {
            "kpis": {
                "credits": {
                    "chart": json.dumps(
                        {
                            "labels": [
                                "A", "B", "C"
                            ],
                            "datasets": [
                                {
                                    "data": [1, 2, 3],
                                    "backgroundColor": ["#0EA5E9", "#F43F5E", "#CBD5E1"],
                                },
                            ],
                        },
                    ),
                },
            },
        }
    )
    return context

In the template this way:

{% component "components/chart/bar.html" with data=kpis.credits.chart options=kpis.credits.options %}{% endcomponent %}

This is especially helpful in doughnut charts (although not officially supported yet) as each dougnut section needs to have different colors:
components/chart/doughnut.html

<div class="relative w-full{% if class %} {{ class }}{% endif %}">
  <canvas class="chart" {% if options %}data-options="{{ options }}"{% endif %} data-type="doughnut" data-value="{{ data }}" {% if width %}width="{{ width }}"{% endif %} {% if height %}height="{{ height }}"{% endif %}></canvas>
</div>

@lukasvinclav lukasvinclav reopened this May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants