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

Plot band

3 Answers 182 Views
Charts
This is a migrated thread and some comments may be shown as answers.
Zaheir
Top achievements
Rank 1
Zaheir asked on 13 Apr 2017, 11:05 PM

I am using ASP.NET MVC Kendo UI to create a chart through using mvc code to build the chart using Plot band but its hard coded in the example below.  How can I change the plot band dynamically using the sample code provided

<div class="demo-section k-content wide">
    @(Html.Kendo().Chart<Kendo.Mvc.Examples.Models.ElectricityProduction>()
        .Name("chart")
        .Title("Spain electricity production (GWh)")
        .Legend(legend => legend
            .Position(ChartLegendPosition.Right)
        )
        .DataSource(ds => ds
            .Read(read => read.Action("_SpainElectricityProduction", "Bar_Charts"))
            .Sort(sort => sort.Add("Year").Ascending())
        )
        .Series(series =>
        {
            series.Column(model => model.Nuclear).Name("Nuclear");
            series.Column(model => model.Hydro).Name("Hydro");
            series.Column(model => model.Wind).Name("Wind");
        })
        .CategoryAxis(axis => axis
            .Categories(model => model.Year)
            .MajorGridLines(lines => lines.Visible(false))
        )
        .ValueAxis(axis => axis.Numeric()
            .Labels(labels => labels.Format("{0:N0}"))
            .MajorUnit(10000)
            .Max(70000)
            .Line(line => line.Visible(false))
            .PlotBands(bands => {
                bands.Add().From(10000).To(30000).Color("#c00").Opacity(0.3);
                bands.Add().From(30000).To(30500).Color("#c00").Opacity(0.8);
            })
        )
        .Tooltip(tooltip => tooltip
            .Visible(true)
            .Format("{0:N0}")
        )
    )
</div>

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 17 Apr 2017, 12:25 PM
Hello ,

The plotBand can be changed dynamically using the setOptions method of the Chart:

http://docs.telerik.com/kendo-ui/api/javascript/dataviz/ui/chart#methods-setOptions

I made an example demonstrating how the plotBands can be changed dynamically. Please have in mind that the example is using the jQuery version, but the MVC implementation is similar as the approach is using client methods:

 http://dojo.telerik.com/URoyI

I hope this will help to achieve the desired result.

Regards,
Stefan
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data (charts) and form elements.
0
Zaheir
Top achievements
Rank 1
answered on 17 Apr 2017, 01:50 PM

Thank you Stefan,

  I have seen this example on the Telerik website.  Can you help me with how I would be able to do this using client methods .  Can this be done dynamically based on an event that can be added to kendo chart in MVC to change the plotBand?

0
Stefan
Telerik team
answered on 18 Apr 2017, 12:19 PM
Hello ,

The same logic which is executed when the button is clicked can be executed on the desired event. One thing that has to be taken into account is that the Chart have to be available before executing the function.

Also, as mentioned in the documentation some of the events of the Chart are not suitable for the setOptions method as it can cause endless loops. For example, it is not recommended to use it on the dataBound and dataBinding events, as the method will fire them as well.

Regards,
Stefan
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data (charts) and form elements.
Tags
Charts
Asked by
Zaheir
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Zaheir
Top achievements
Rank 1
Share this question
or