Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
D3 line chart change the color dyanmicallly based on mock data in react js

I am new to d3 I wanted to change the color of the graph, when caseDifference is Same I need to show it as grey color. when caseDifference is Increase I need to show it as green color. when caseDifference is Decrease I need to show it as Red color. I debugged the code and found that in css they are changing the color so I changed .trend__line to green color. But I need to change dyanmically on the basis of caseDifference. Providing code snippet and sandbox below.

https://codesandbox.io/s/n6ssk7?file=/src/components/Trend.js

<defs>
        <clipPath id="selected-region">
          <rect x={0} y={0} width={selectedWidth} height={height} />
        </clipPath>
      </defs>
      <g
        ref={yAxisRef}
        className="trend__y-axis trend__axis"
        transform={`translate(${yAxisWidth}, 0)`}
      />



.trend__area {
  fill: #f7d5d0;
}

.trend__line {
  fill: none;
  stroke: green;
  stroke-width: 2;
}





[
  { "Date": "2020-01-21", "Confirmed": 1, "caseDifference": "same" },
  { "Date": "2020-01-22", "Confirmed": 10, "caseDifference": "Increase" },
  { "Date": "2020-01-23", "Confirmed": 5, "caseDifference": "Decrease" },
  { "Date": "2020-01-24", "Confirmed": 2, "caseDifference": "Decrease" },
  { "Date": "2020-01-25", "Confirmed": 3, "caseDifference": "Increase" },
  { "Date": "2020-01-26", "Confirmed": 5, "caseDifference": "Increase" },
  { "Date": "2020-01-27", "Confirmed": 5, "caseDifference": "same" },
  { "Date": "2020-01-28", "Confirmed": 5, "caseDifference": "same" },
  { "Date": "2020-01-29", "Confirmed": 5, "caseDifference": "same" }]
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!