Dates are not being shown correctly for ChartCategoryAxisItem

2 Answers 39 Views
Charts
Christian
Top achievements
Rank 1
Iron
Christian asked on 09 Dec 2021, 05:34 PM

Hello Guys

Here I bring another question regarding to Date type on charts when displaying data.

I am supposed to have on X axis the fist and the last label for the dates, but despite of the last date is 2021-10-18T00:00:00+00:00, it is not being shown.

should dates have a special format or something?

Here is the code :


const data = [
  {
    date: '2021-08-02T00:00:00+00:00',
    score: 631,
  },
  {
    date: '2021-08-09T00:00:00+00:00',
    score: 624.25,
  },
  {
    date: '2021-08-23T00:00:00+00:00',
    score: 596.6,
  },
  {
    date: '2021-09-13T00:00:00+00:00',
    score: 505.666656,
  },
  {
    date: '2021-09-27T00:00:00+00:00',
    score: 417,
  },
  {
    date: '2021-10-04T00:00:00+00:00',
    score: 485.666656,
  },
  {
    date: '2021-10-18T00:00:00+00:00',
    score: 548,
  },
];

const ChartContainer = () => (
  <Chart>
    <ChartCategoryAxis>
      <ChartCategoryAxisItem
        majorGridLines={{ visible: false }}
        justified={true}
        categories={data.map((d) => d.date)}
        labels={{ rotation: 'auto', step: data.length - 1 }}
        type="date"
      />
    </ChartCategoryAxis>
    <ChartValueAxis>
      <ChartValueAxisItem
        majorGridLines={{
          visible: false,
        }}
        title={{
          text: 'Scaled Score',
        }}
      />
    </ChartValueAxis>

    <ChartSeries>
      <ChartSeriesItem
        type="line"
        data={data.map((d) => d.score)}
        missingValues="interpolate"
      />
      <ChartSeriesItem
        type="area"
        data={data.map((d) => d.score)}
        missingValues="interpolate"
        color="rgb(214 237 247)"
      />
    </ChartSeries>
  </Chart>
);

Stackblitz live demo

 

Thanks for your help

 

 

Christian
Top achievements
Rank 1
Iron
commented on 09 Dec 2021, 05:47 PM

Also, if you look at the data array, the fist object has a date of 2021-08-02, but chart renders 8/1 (August 1st), Which is wrong, it should render 8/2 (August the 2nd)

2 Answers, 1 is accepted

Sort by
0
Filip
Telerik team
answered on 13 Dec 2021, 03:13 PM

Hello, Christian,

It seems that the reason for the X-axis to not display all of the dates was because it was skipping a week, this can be handled by adding the baseUnit property, which sets the base time interval for the axis labels and setting it to days like shown in this example:

https://stackblitz.com/edit/react-nnzrce-dlhqav?file=app/main.jsx

Another thing that we did here, was to change the step as well, which can be set to the value that works best for you.

Regarding your second question, the reason for displaying the wrong date could be because of the +00 00 in the date format, which when parsed to your time shows the previous day.

I hope this helps.

Regards, Filip Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Christian
Top achievements
Rank 1
Iron
commented on 13 Dec 2021, 05:25 PM | edited

Hi Filip, thanks for your answer,

What I am trying to understand is why in the scenario of using data1 the chart looks good for what I try to do: 

see capture.PNG, 

 

but when there is the scenario for data2, the chart labels does not show the second one at the end of the chart X axis, like shown on Capture1.PNG.

 

 

0
Christian
Top achievements
Rank 1
Iron
answered on 14 Dec 2021, 06:06 PM
I could figure it out, the problem was that I was not putting the prop weekStartDay to match the dates I was expecting per week


Tags
Charts
Asked by
Christian
Top achievements
Rank 1
Iron
Answers by
Filip
Telerik team
Christian
Top achievements
Rank 1
Iron
Share this question
or