XML Data Visualization with jQuery Chart

In this post, we will introduce you how to add the jqxChart widget to your web page and build it from XML Data.

Create a HTML file called Chart.html that contains the following HTML code:

<html lang="en">
    <title id='Description'>jqxChart Line Series Example</title>
    <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
    <script type="text/javascript" src="../../scripts/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxchart.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            // prepare the data
            var source = { datafields: [
                    { name: 'Date' },
                    { name: 'Quantity' },
                    { name: 'Description' }
                root: "Orders",
                record: "Order",
                datatype: "xml",
                url: '../sampledata/orderdetails.xml'

            var dataAdapter = new $.jqx.dataAdapter(source);

            // prepare jqxChart settings
            var settings = {
                title: "Order Details",
                showLegend: true,
                source: dataAdapter,
                        dataField: 'Date',
                        formatFunction: function (value) {
                            var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
                            return months[new Date(value).getMonth()];
                        showGridLines: true
                colorScheme: 'scheme04',
                            type: 'column',
                                displayValueAxis: true,
                                axisSize: 'auto',
                                tickMarksColor: '#888888'
                            series: [
                                    { dataField: 'Quantity', displayText: 'Quantity' }
            // setup the chart
<body class='default'>
    <div id='jqxChart' style="width: 680px; height: 400px">

In the Head section of the page, we include the jQuery javascript file, the jQWidgets core framework file – jqxcore.js, the jQWidgets data binding file – jqxdata.js, the main jqxChart plug-in file – jqxchart.js file, and the base jQWidgets stylesheet – jqx.base.css. On to the body of the page. we create a DIV tag as the placeholder for the chart with a unique ID = “jqxChart”. The chart is then instantiated using the jqxChart constructor function. The constructor takes in the following parameters: source – dataAdapter object, categoryAxis and seriesGroups objects, colorScheme(available values are from ‘scheme01’ to ‘scheme11’), showLegend(displays the legend section in the chart) and the Chart title. In the source object initialization, we specify the datafields array, the root and record properties, the url(points to a xml data file) and we set the datatype to ‘xml’.

This is the XML Data file that we use to build the Chart.

<?xml version="1.0" encoding="utf-8" ?>

In the seriesGroup object, the series group type is ‘column’ which means that the data will be visualized by columns. The valueAxis definition specifies the appearance of the Y-axis. This series group contains one serie that will render data corresponding to the Quantity dataField that it binds to. In this example we bind the Category Axis (horizontal X axis) to the Date property of our data source. jquery chart order details

About admin

This entry was posted in JavaScript, JavaScript Plugins, JavaScript Widgets, jQuery, jQuery Plugins, jQuery UI, jQuery UI Plugins, jQuery UI Widgets, jQuery Widgets, jQWidgets, jqxChart and tagged , , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply