Change series legend at runtime

1 Answer 13 Views
Chart
AP
Top achievements
Rank 1
Veteran
AP asked on 29 Sep 2021, 02:11 PM

I have a chart which, depending on a button group selection, will display a different data item in a line series. This is handled server-side, with the chart definition not needing to be changed.

However, I do need to change the name displayed on the value axis and legend name.

I can do this by using the following code:-

var specChart = $("#chortcategorytrendchart").data("kendoChart");

            specChart.options.valueAxis[1].title.text = sName;

            specChart.options.series[1].name=sName;

            specChart.refresh();

 

This works, but I also need to call the chart datasource.read:-

$('#chortcategorytrendchart').data("kendoChart").dataSource.read();

When I do this, the value axis title remains changed correctly, but the series name in the legend reverts to the default setting in the chart definition.

It doesn't make a difference if the read is called before or after the chart refresh.

I am using version 2021.2.511. How can I stop the read call changing the series name back?

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 04 Oct 2021, 11:24 AM

Hello,

 

Thank you for writing to us.

Frankly said, these kind of implementations can be very tedious and we highly suggest that you create several Charts on the page to accommodate the different options selected by the user. Then, you can toggle the visibility of the Charts depending on the choice.

Otherwise, you can check setOptions and setDataSource methods, but I am afraid there is no direct solution for canceling the read action in this case:
https://docs.telerik.com/kendo-ui/api/javascript/dataviz/ui/chart/methods/setoptions

Does this info make sense? Let me know if I can assist with anything additional.

 

Regards,
Eyup
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/.

AP
Top achievements
Rank 1
Veteran
commented on 04 Oct 2021, 02:52 PM

I did manage to get this working. I added a databound event to the chart, and then used the redraw function to change the titles in this call, which is working.

It seems like a bit of a bug that the data load reverts the series name

Tags
Chart
Asked by
AP
Top achievements
Rank 1
Veteran
Answers by
Eyup
Telerik team
Share this question
or