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.

Line color based on value

See original GitHub issue

Is your feature request related to a problem? Please describe. I couldn’t find a way to set color on line based on value. I’d really like to set a different color on the line when it’s below zero.

Describe the solution you’d like Set the color as a function with value as parameter.

Describe alternatives you’ve considered const color = value => value >= 0 ? "#00ff00" : "#ff0000";

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
JeremyBellaichecommented, Oct 7, 2022

Hi,

I’m able to get this kind of charts using apexcharts. I guess that’s what you’re looking for :

image

First, I’ve a variable “data” containing all the values I will display on the chart. With that, I’ve created a function :

const generateColors = (data) => {
        return data.map((d, idx) => {
            let color = d > 0 ? '#22c55f': '#ef4544';

            return {
                offset: idx / data.length * 100,
                color,
                opacity: 1
            }
        })
    }

and my options looks like this :

const options = {
        chart: {
            type: 'line',
            height: 350,
            width: "auto",
        }, 
        // ...
        fill: {
            type: 'gradient',
            gradient: {
                shadeIntensity: 1,
                opacityFrom: 0.7,
                opacityTo: 0.9,
                colorStops: generateColors(data)
            }
        } 
}

Hope that can help !

3reactions
junedchhipacommented, May 15, 2019

I assume you’re talking about a line like this Screen Shot 2019-05-15 at 11 12 22 PM

Unfortunately, the line chart doesn’t currently support having a different color based on value. Hence, providing dataPointIndex will serve no purpose here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Excel: Change the row color based on cell value - Ablebits
How to change a row color based on a number in a single cell · Create a new formatting rule by clicking Conditional...
Read more >
Change chart color based on value in Excel - ExtendOffice
Select the bar chart or column chart, then click Kutools > Charts > Color Chart by Value. Then in the popped-out dialog, set...
Read more >
How to Change Line Chart Color Based on Value - ExcelNotes
Step 5: Now the Line chart is colored based on value. Step 6: Part of the line is gray, to change it to...
Read more >
Highlight Rows Based on a Cell Value in Excel (Conditional ...
Click the 'Format' button. In the dialog box that opens, set the color in which you want the row to get highlighted. Click...
Read more >
Power bi change color based on value [With 13 real examples]
Power BI changes data label color based on the value · Now, Select the Format style as Rules and choose the column field...
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