Chartjs-How to use date in x value for Object[] in chartjs dataset, I am getting an error: 'TS2322: Type 'string' is not assignable to type 'number'.'

1👍

You can pass your own type to the ChartConfiguration interface as a second parameter like so:

const lineChartData: ChartConfiguration<"line", { x: string, y: number }[]> = {
  type: "line",
  data: {
    labels: [],
    datasets: [
      {
        data: [
          { x: "test", y: 55 },
          { x: "hi", y: 20 },
        ],
      },
    ],
  },
};

Typescript playground link

Leave a comment