v2 Line chart with individual point colors?

Hi there,

I’m wondering whether it is possible to have points on a line chart with each a different color (background/border).

Not sure whether this would be something that could be done via a dataset’s metaDataset?
It’s possible to grab a particular point’s color in the metaDataset via chart.data.datasets[0].metaDataset._points[0]._view.backgroundColor, but how would I be able to specify each point’s individual color? (preferrably upon instantiation of the chart already)

Thanks in advance for your feedback!

Kind regards,
David

Author: Fantashit

1 thought on “v2 Line chart with individual point colors?

  1. Hi @etimberg,

    thanks for your quick reply!

    I should have mentioned I gave this a go already… This looks like the perfect solution, however that doesn’t seem to work though: is this broken in Chart.js 2.0-dev?

    Quick example:

    var data = {
        labels: ['x1', 'x2', 'x3', 'x4'],
        datasets: [
            {
                data: [0, 1, 2, 3],
                backgroundColor: ['red', 'green', 'blue', 'yellow']
            }
        ]
    };
    
    var chart = new Chart(ctx, {
        type: 'line',
        data: data
    });

    …just gives me a chart with 4 gray points.

    Thanks in advance for your feedback!

    Kind regards,
    David

Comments are closed.