To get started with a JavaScript library I suggest downloading one and giving it a try.
Let’s take Ext js. Download it here:
http://www.extjs.com/products/extjs/download.php
Extract the files to your IIS server or open the folder in Visual Studio as an existing web application. Browse to examples->Chart->charts.htm and press play. You cannot just double click this file and open in a browser. Go head and try – the flash player does not allow it. So run that page by right clicking it in VS.NET and view in browser.
Cool charts huh?
How did that happen?
Check out the source of the page. Look at the header.
<!-- GC -->
<!-- LIBS -->
<script type="text/javascript" src="../../adapter/ext/ext-base.js"></script>
<!-- ENDLIBS -->
<script type="text/javascript" src="../../ext-all.js"></script>
<script type="text/javascript" src="charts.js"></script> |
You can see that the page pulls in ext-base.jd and ext-all.js as well as a chart.js.
Chart.js just contains the actual data for the chart and the markup as well:
Ext.chart.Chart.CHART_URL = '../../resources/charts.swf';
Ext.onReady(function(){
var store = new Ext.data.JsonStore({
fields:['name', 'visits', 'views'],
data: [
{name:'Jul 07', visits: 245000, views: 3000000},
{name:'Aug 07', visits: 240000, views: 3500000},
{name:'Sep 07', visits: 355000, views: 4000000},
{name:'Oct 07', visits: 375000, views: 4200000},
{name:'Nov 07', visits: 490000, views: 4500000},
{name:'Dec 07', visits: 495000, views: 5800000},
{name:'Jan 08', visits: 520000, views: 6000000},
{name:'Feb 08', visits: 620000, views: 7500000}
]
});
// extra extra simple
new Ext.Panel({
title: 'ExtJS.com Visits Trend, 2007/2008 (No styling)',
renderTo: 'container',
width:500,
height:300,
layout:'fit',
items: {
xtype: 'linechart',
store: store,
xField: 'name',
yField: 'visits',
listeners: {
itemclick: function(o){
var rec = store.getAt(o.index);
Ext.example.msg('Item Selected', 'You chose {0}.', rec.get('name'));
}
}
}
});
Complex stuff at first glance, but first look at the data and then match up the items with the extjs markup.
Edit the data. Change the datanames. play around with it a bit and break it.
As always be sure to attend the Client Side Coding Master’s Series class.