Book Image

Kendo UI Cookbook

By : Sagar Ganatra
Book Image

Kendo UI Cookbook

By: Sagar Ganatra

Overview of this book

Table of Contents (18 chapters)
Kendo UI Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Changing the chart type dynamically


In this recipe, we will take a look at how the type and skin of the chart can be changed at runtime. For example, if you have projected a column chart and you want to change it to, say, a line chart, then changes can be made to the series and the chart will be updated. This is useful in cases where you would like to visually represent data in various forms but you can't because of the space constraint. In this recipe, we will construct the chart using the data attributes instead of using the kendoChart function. This is another way of constructing a chart. Also, we will use the Model View ViewModel pattern to make changes to the chart when the user changes its type or skin. This pattern obliterates the use of adding event handlers and, instead, relies on listening to model changes to update the chart dynamically.

How to do it…

Let's create a chart by specifying various options as data attributes:

<div id="chartArea" data-role="chart" data-title="{text...