react-chartjs-2 icon indicating copy to clipboard operation
react-chartjs-2 copied to clipboard

Help Wanted With Labels disappearing when width is 100%

Open clarson1229 opened this issue 6 years ago • 1 comments

Hello, Below is a screenshot of what I want my line chart to look like all the time with just the labels showing up for the start of each day. I can ensure that this works 100% of the time if I set the width to an exact pixel width. But when I set the width to 100% and the chart is viewed on different monitors those labels drop off. Show in the other two screenshots.

Working Correctly image

Not working Correctly image Not Working Correctly image

The data set I'm working with is DateTime Stamped Data for every 15 minutes and then a value. I do not want a label for every 15 minutes so I wrote a callback that takes the Label and only displays it if the time is 00:00:00 signifying the start of a new day.

xAxes:[
            {
              ticks: {
                  callback: value => {
                        var dateTime = value.split("T");
                         if (dateTime[1]=== '00:00:00'){
                             var tYearMonthday = dateTime[0].split('-');
                              return `${tYearMonthday[1]}/${tYearMonthday[2]}`;
                         }else{
                              return '';
                          } 
                    }
                 }
              }
      ]

This seems to work but I am having issues with the labels falling off the chart as shown in the first screenshots. My first thought is that there is too much data being fed in for the chart to handle it so the labels are falling off but I'm not sure. Any help would be appreciated.

clarson1229 avatar Jun 23 '20 16:06 clarson1229

Solved the issue by making the Axes have the type of time and then display the unit based on days

clarson1229 avatar Jun 23 '20 16:06 clarson1229