If you know jQuery, and want to include data-viz elements in your web page without all the hassle, you are at the right place. I am going to give you a gist of how Kendo works with jQuery to create robust data-viz elements.
We will build a ratings pie chart, step by step. Final product is shown below.
First things first. You need to download Kendo UI. There are several paid versions, and a free (trial) version. Trial is more than enough for trying it out.
Download Kendo UI for a trial period from here. You will have to sign up to download it.
Extract the downloaded ZIP archive to an easily accessible location. We are going to need it’s js and css folders.
Kickstart the project by creating a new folder, say kendo-pie. Copy the downloaded js and css folders in kendo-pie.
Now, create a new HTML file in kendo-pie, say index.html. This is our main webpage. The pie chart will reside here.
4. The HTML
Open index.html with your favourite text editor. Add some starter code.
Give it a title, say Overall Ratings. Link all the necessary js and css files, inside head.
Time to populate the body. Create a wrapper (div), with id overall. The actual chart element and it’s script will reside in this wrapper. Create the chart div inside the wrapper, with id chart. Give it some style with a style attribute.
The above goes inside body, and the whole thing up-to this point looks something like this:
5. The jQuery
Create a script element inside the wrapper, and add some starter jQuery code.
Inside the document-ready function, select the chart element with jQuery’s id selector, and apply kendoChart() method.
6. The Kendo
kendoChart() takes a configuration object as an argument. This configuration object is used to describe the chart and include data (local or remote) to be represented.
Let’s contsruct the configuration object:
- Add title property.
2. Add legend property.
3. Add some defaults.
4. Add series properties: type of chart and local data.
5. Add tooltip property.
kendoChart() method is ready. So is the script. Coding part is complete. Wrapper should look like this.
These were the basic steps to create a pie chart using jQuery and Kendo, mostly Kendo. Now, open index.html in browser, and you should see output as below.
I hope the above steps were helpful in giving you a basic idea about Kendo UI. It’s up to you now to tweak the chart however you want, or create a new element altogether. There are loads available. Docs are available here, and demos here.
Note: This post is authored by Mr. Abhay Kumar, interning with GTM Catalyst (distributor of Telerik controls in India).