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

Multiple series names

2 Answers 136 Views
Charts
This is a migrated thread and some comments may be shown as answers.
Etra
Top achievements
Rank 1
Etra asked on 04 Feb 2015, 03:16 PM
Hi,

I am trying to set the name for multiple series on the legend of the chart, but I do not want to set them via code, I want to retreive it from the server side.
My .aspx code is:

 <div id="divChart">
        <% 
            Html.Kendo().Chart<SmartClient.datamodel.publicLightingOptimization>()
            .Name("chart")
            .CategoryAxis(axis => axis.Labels(l => l.Rotation(90)).Type(ChartCategoryAxisType.Date).Date().MajorGridLines(lines => lines.Visible(true)).BaseUnit(ChartAxisBaseUnit.Minutes).BaseUnitStep(60).MinorGridLines(lines => lines.Visible(false)))
            .Tooltip(tooltip => tooltip.Visible(true))
            .Series(s => s.Line("command0", "instant").Style(ChartLineStyle.Step))
            .Series(s => s.Line("command1", "instant").Style(ChartLineStyle.Step))
            .Series(s => s.Line("command2", "instant").Style(ChartLineStyle.Step))
            .Series(s => s.Line("command3", "instant").Style(ChartLineStyle.Step))
            .Series(s => s.Line("command4", "instant").Style(ChartLineStyle.Step))
            .Series(s => s.Line("energy_consumption", "instant").Style(ChartLineStyle.Step))
            .Series(s => s.Line("energy_cost", "instant").Style(ChartLineStyle.Step))
            .Series(s => s.Line("qos", "instant").Style(ChartLineStyle.Step))
            .Legend(l => l.Position(Kendo.Mvc.UI.ChartLegendPosition.Bottom))
            .DataSource(ds => ds.Read(read =>  read.Action("GetPLValues", "Optimizations").Type(HttpVerbs.Get)))
            .Render();  
        %>
    </div>

How can I set those names from the server side code?

Thank you in advance


2 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 06 Feb 2015, 11:08 AM
Hello,

I am not sure if I understand the question but you should set the series name option to set the name in the legend:
.Series(s => s.Line("command0", "instant").Name("command0 name").Style(ChartLineStyle.Step))
If the name should be set dynamically based on the loaded data then you can use the dataBound event to change the options:
function onDataBound(e) {
    var data = this.dataSource.data();
    var series = this.options.series;
    for (var i = 0; i < series.length; i++) {
        series[i].name = getNameForField(series[i].field, data);
    }
}


Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Etra
Top achievements
Rank 1
answered on 09 Feb 2015, 12:40 PM
Thank you, it worked.

Just for completing your solution, on the definition of the Html.Kendo().Chart y added:
.Events(events => events.DataBound("onDataBound"))

Tags
Charts
Asked by
Etra
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Etra
Top achievements
Rank 1
Share this question
or