JSFiddle - React, Tailwind, and code Playground

by rnsbhargav

HTML

<script src="https://cdn.jsdelivr.net/npm/chart.js@3.8.0"></script>
<canvas id="mychart" width="10" height="6"></canvas>

JavaScript

const options = {
      type: 'line',
      data: {
        labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
        datasets: [{
          label: '# of Votes',
          data: [12, 19, 3, 5, 2, 3],
          segment: {
            borderColor: (ctx) => (ctx.p0.parsed.y < ctx.p1.parsed.y ? 'green' : 'red')
          }
        }]
      },
      options: {}
    }

    const ctx = document.getElementById('mychart').getContext('2d');
    new Chart(ctx, options);