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

Add series dynamically

2 Answers 178 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Martinez
Top achievements
Rank 1
Martinez asked on 06 Oct 2011, 05:32 PM
Hi,
Please, Could you tell me how I can add series dynamically?

<%= Html.Telerik().Chart(Model)
    .Name("chart")
    .Series(series => {
            series.Bar(s => s.RepSales).Name("Representative Sales");
    })
    .CategoryAxis(axis => axis
        .Categories(s => s.DateString)
    )
%>

I wait for your comments, thanks.

2 Answers, 1 is accepted

Sort by
0
Hristo Germanov
Telerik team
answered on 10 Oct 2011, 10:02 AM
Hello Martinez,

Thank you for contacting us.

You need to hook up to "onLoad" client-side event and in this method you can modify the series of the chart.

<script type="text/javascript">
    function onLoad(e) {
        var chart = $("#chart").data("tChart");
        chart.options.series.push({ color: "red", data: [//your data here], name: "Custom", type: "bar" });
        chart.refresh();
    }
</script>
 
<%= Html.Telerik().Chart(Model)
    .Name("chart")
    .Series(series => {
            series.Bar(s => s.RepSales).Name("Representative Sales");
    })
    .CategoryAxis(axis => axis
        .Categories(s => s.DateString)
    )
    .ClientEvents(events => events.OnLoad("onLoad"))
%>

Greetings,
Hristo Germanov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Keith
Top achievements
Rank 1
answered on 28 Apr 2012, 03:52 AM
Hello Hristo,

This is great.  I'm looking to dynamically add and remove series from a chart, however, and while the push works well, I cannot seem to find any documentation on the removal of a series.  Is that possble via javascript as well?

Thanks so much.

Keith
Tags
Chart
Asked by
Martinez
Top achievements
Rank 1
Answers by
Hristo Germanov
Telerik team
Keith
Top achievements
Rank 1
Share this question
or