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.

Linear gradient doesn't work on backgroundColor prop

See original GitHub issue

Sandbox: https://codesandbox.io/s/distracted-feynman-tnn96

function createGradient(ctx: CanvasRenderingContext2D, area: ChartArea) {
  const colorStart = faker.random.arrayElement(colors);
  const colorMid = faker.random.arrayElement(
    colors.filter((color) => color !== colorStart)
  );
  const colorEnd = faker.random.arrayElement(
    colors.filter((color) => color !== colorStart && color !== colorMid)
  );

  const gradient = ctx.createLinearGradient(0, area.bottom, 0, area.top);

  gradient.addColorStop(0, colorStart);
  gradient.addColorStop(0.5, colorMid);
  gradient.addColorStop(1, colorEnd);

  return gradient;
}

  useEffect(() => {
    const chart = chartRef.current;

    if (!chart) {
      return;
    }

    const chartData = {
      ...data,
      datasets: data.datasets.map((dataset) => ({
        ...dataset,
        borderColor: createGradient(chart.ctx, chart.chartArea),
        fill: 1,
        backgroundColor: createGradient(chart.ctx, chart.chartArea).  <---- Doesn't add gradient background
      }))
    };

    setChartData(chartData);
  }, []);

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

0reactions
drydenwilliamscommented, Mar 27, 2022

Legend, thank you @dangreen! Missed that one 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

linear-gradient not working in Chrome - Stack Overflow
For instance: background: -webkit-gradient(linear, left top, right top, color-stop(0% ...
Read more >
linear-gradient() - CSS: Cascading Style Sheets | MDN
The linear-gradient() CSS function creates an image consisting of a progressive transition between two or more colors along a straight line.
Read more >
Background Gradient Not Working - HTML & CSS - SitePoint
Hey Friends! I have been trying to add some gradient to the body of my template and after a couple of goes it...
Read more >
CSS Gradients - CSS-Tricks
Gradients are background-image. While declaring the a solid color uses background-color property in CSS, gradients use background-image . This ...
Read more >
Setting Backgrounds & Gradients - Learn to Code HTML & CSS
CSS. Background Color; Background Image; Gradient Backgrounds ... Either property will work, and which one you decide to use depends on your preference...
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