Skip to content

[Bar chart] Legend color markers are not displayed when a function is used for chart color #1416

@AndreaMinato

Description

@AndreaMinato

This issue is based on #725 that was closed after resolving the problem for all chart but bar ones.

I opened this issue because I really need that feature to work even in bar charts.

I see that in the commit that closed the issue you have added

  w.globals.colors = this.predefined()
    } else {
      w.globals.colors = w.config.colors
+
+      // if user provided a function in colors, we need to eval here
+      if (
+        w.globals.axisCharts &&
+        w.config.chart.type !== 'bar' &&
+       Array.isArray(w.config.colors) &&
+      w.config.colors.length > 0 &&
+     w.config.colors.length === w.config.series.
+     // colors & series length needs same
+   ) {
+     w.globals.colors = w.config.colors.map((c, i) =>
+       return typeof c === '
+         ? c({
+             value: w.globals.axisCharts
+               ? w.globals.series[i][0]
+                 ? w.globals.series[i][0]
+                 : 0
+               : w.globals.series[i],
+             seriesIndex: i,
+             w: w
+           })
+        : c
+    })
+  }
+}
+}

    if (w.config.theme.monochrome.enabled) {

And I'm wondering why you add the w.config.chart.type !== 'bar' condition to the clause.

I tried to run locally the apexcharts.js project to exclude that check but it's not the cause, since your response on the closed issue I believe that you know that this isn't working for bar charts and maybe you have an idea about how to fix it.

May I ask you further informations and if needed I can help you troubleshot this behaviour

Thank for your work

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions