This is a migrated thread and some comments may be shown as answers.

Limit number of labels in chart

3 Answers 799 Views
Charts
This is a migrated thread and some comments may be shown as answers.
G
Top achievements
Rank 1
G asked on 25 Jul 2019, 01:45 PM

(this question was originally asked on stackOverflow https://stackoverflow.com/questions/57198635)

I want to limit the number of labels in the categoryAxis of my kendo chart.

So far I've calculated an automatic step from the number of data points and the width of the chart and it's worked great. But I'm starting to receive some data that triggers Kendo's automatic date label format switch to minutes and now I have 60 times more labels than I should, which creates huge amounts of lag (and makes the chart unreadable).

I've looked into setting a maxDateGroup, but that actually reduces the number of categories, thus ignoring some of the data.
I found a way to get the number of labels on the forums :

 

```
// get reference to the chart widget

var chart = $("#chart").data("kendoChart");

// get the categories length

chart._plotArea.categoryAxis.children.length

```

But it requires to draw the chart first, then read the property, then adjust accordingly and redraw the chart. Which isn't exactly ideal.
So I'm wondering if there is a way to set a max number of labels, or maybe limit labels to 1 per category ? Or any other trick-shot really :)

Note : this automatic switch works great for data that actually is recorded every minutes, but the series that's causing me problems is recorded every 30 minutes. Maybe there is some workaround here but I can't recall where I saw how to fiddle with these properties.

3 Answers, 1 is accepted

Sort by
0
G
Top achievements
Rank 1
answered on 25 Jul 2019, 01:46 PM
(I think I posted this in the wrong forum, sorry !)
0
Accepted
Marin Bratanov
Telerik team
answered on 26 Jul 2019, 02:46 PM
Hi,

The answer I see in the StackOverflow thread is the approach to go - you will need to configure the chart based on the data you have. Since you are using the jQuery chart you can get the data, examine it, and only then instantiate the chart with the required settings.

As to why there is no "cleaner" way of doing that - because a feature where the labels are limited would be heuristic (that is, non-deterministic). There is no certain way of producing a good quality chart and having a limit on the labels (categories). Generally, a label must be rendered for each category on the x-axis (be those discreet categories or grouped dates). The Step and Skip settings for the labels are deterministic in their behavior, because they do not require that the chart knows what data and visualization will need to be produced.

If you can devise a way to determine such a limit, you can use the visual function of the labels and return no labels according to your logic, and otherwise you could use the createVisual(): https://docs.telerik.com/kendo-ui/api/javascript/dataviz/ui/chart/configuration/categoryaxis.labels#categoryaxislabelsvisual.


Regards,
Marin Bratanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
G
Top achievements
Rank 1
answered on 29 Jul 2019, 08:36 AM

Ok, I think I understand your explanation... I will try the workaround then !

Thank you

Tags
Charts
Asked by
G
Top achievements
Rank 1
Answers by
G
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or