chartjs / Chart.js

Simple HTML5 Charts using the <canvas> tag
https://www.chartjs.org/
MIT License
63.92k stars 11.89k forks source link

fix(bar_chart): data typing #11734

Closed Oleksii14 closed 2 months ago

Oleksii14 commented 3 months ago

Original issue: https://github.com/apertureless/vue-chartjs/issues/1058

LeeLenaleee commented 2 months ago

Why would the default data point need adjustment, you are able to provide your own custom data types to chart.js:

import { Chart, ChartData } from 'chart.js';

var data: ChartData<'polarArea', {x: Date, y: {foo: boolean}}[]> = {
  labels: [],
  datasets: [{
    data: [{ x: new Date(), y: {foo: false} }],
  }],
};

var ctx = document.getElementById("myChart") as HTMLCanvasElement;
var myChart = new Chart(ctx, {
    type: 'polarArea',
    data: data,
});
Oleksii14 commented 2 months ago

Why would the default data point need adjustment, you are able to provide your own custom data types to chart.js:

import { Chart, ChartData } from 'chart.js';

var data: ChartData<'polarArea', {x: Date, y: {foo: boolean}}[]> = {
  labels: [],
  datasets: [{
    data: [{ x: new Date(), y: {foo: "false"} }],
  }],
};

var ctx = document.getElementById("myChart") as HTMLCanvasElement;
var myChart = new Chart(ctx, {
    type: 'polarArea',
    data: data,
});

You're right. The original issue should be resolved directly in the Vue.js implementation of the chart components. Thanks for the reply. I am closing this PR.