question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[FEATURE] - Line Chart with Colored Filled Regions (instead of a single color only)

See original GitHub issue

Expected Behavior

Most color options in chart.js accept either a single color or an array of colors to control the corresponding element. For example, you can configure a line chart to have different colored points using the pointBackgroundColor option and passing in an array.

However, this same concept is currently not supported for the line chart fill color (e.g. backgroundColor)

Current Behavior

The new behavior would allow the line chart backgroundColor option to accept an array of colors to produce colored fill areas. Here is an example.

Possible Solution

Based on the tagged v2.5.0 source, logic could be added to Chart.elements.Line.draw() to build a canvas linear gradient based on the position of each point and use this as the ctx.fillStyle instead of a single color.

Here is a codepen example where I have added the logic in at runtime.

Context

I needed this capability in some charts used within my company. I figured if I needed it then others might need it as well.

Environment

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jordanwilliscommented, May 10, 2017

@etimberg Sounds good! Let me review the latest line fill code changes and get back with you on an implementation approach.

0reactions
etimbergcommented, Nov 1, 2019

Added a sample file showing how to use gradients as a fill in #6666. This can be used to implement this case

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vary the colors of same-series data markers in a chart
Set varying colors of data markers (bars, columns, lines, pie or doughnut slices, dots, and other shapes) automatically in an Office chart.
Read more >
Video: Customize a line chart - Microsoft Support
We have added our data to the line chart. Now, let's customize the chart, so it has the details and style we want....
Read more >
Shade the Area Between Two Lines - Excel Line Chart
In this video, we shade the area between two lines of a line chart to visualise the difference clearer.There are many reasons to...
Read more >
A Complete Guide to Area Charts | Tutorial by Chartio
Area charts combine the line chart and bar chart for more specific purposes. Use this guide to learn the best times and ways...
Read more >
Build a Better, Cleaner, More Professional Line Chart
Even a basic line chart can be given a cool makeover with better colors, axes, ... If the chart is titled “Sales” and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found