I've been trying to set x-axis as timescale in react-chartjs-2, but can't get past this following error.
Chart options code snippet:
const options = {
plugins: {...},
scales: {
x: {
ticks: {
autoSkip: true,
maxTicksLimit: 4,
minRotation: 0,
maxRotation: 0,
},
beginAtZero: false,
type: 'time',
time: {
unit: 'month',
},
},
},
},
};
Error: Setting time
property inside scales.x
gives me following error:
Type 'string' is not assignable to type '"timeseries"'.
Does anyone have any clue on how to fix this?
Thank You!
Edit:
I've followed installation steps for date-fns adapter as said here - npm installed necessary dependencies, imported the adapter and added to options, removed beginAtZero property, but the error remains.
const options = {
plugins: {...},
scales: {
x: {
ticks: {
autoSkip: true,
maxTicksLimit: 4,
minRotation: 0,
maxRotation: 0,
},
adapters: {
date: {
locale: 'hr',
},
},
type: 'time',
time: {
unit: 'month',
},
},
},
},
Full error:
Type '{ plugins: { legend: { display: boolean; }; tooltip: { mode: "index"; intersect: boolean; }; }; scales: { x: { ticks: { color: string; autoSkip: boolean; maxTicksLimit: number; minRotation: number; maxRotation: number; }; type: string; adapters: { ...; }; time: { ...; }; }; y: { ...; }; }; hover: { ...; }; }' is not assignable to type '_DeepPartialObject<CoreChartOptions<"line"> & ElementChartOptions<"line"> & PluginChartOptions<"line"> & DatasetChartOptions<"line"> & ScaleChartOptions<...> & LineControllerChartOptions>'.
Types of property 'scales' are incompatible.
Type '{ x: { ticks: { color: string; autoSkip: boolean; maxTicksLimit: number; minRotation: number; maxRotation: number; }; type: string; adapters: { date:
{ locale: string; }; }; time: { unit: string; }; }; y: { ticks: { ...; }; }; }' is not assignable to type '_DeepPartialObject<{ [key: string]: ScaleOptionsByType<keyof CartesianScaleTypeRegistry>; }>'.
Property 'x' is incompatible with index signature.
Type '{ ticks: { color: string; autoSkip: boolean; maxTicksLimit: number; minRotation: number; maxRotation: number; }; type: string; adapters: { date: { locale: string; }; }; time: { unit: string; }; }' is not assignable to type '_DeepPartialObject<{ type: "time"; } & Omit<CartesianScaleOptions, "min" | "max">
& { min: string | number; max: string | number; suggestedMin: string | number; ... 4 more ...; ticks: { ...; }; }> | ... 4 more ... | undefined'.
Type '{ ticks: { color: string; autoSkip: boolean; maxTicksLimit: number; minRotation: number; maxRotation: number; }; type: string; adapters: { date: { locale: string; }; }; time: { unit: string; }; }' is not assignable to type '_DeepPartialObject<{ type: "timeseries"; } & Omit<CartesianScaleOptions, "min" | "max"> & { min: string | number; max: string | number; suggestedMin: string | number; ... 4 more ...; ticks: { ...; }; }>'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"timeseries"'.