Custom Elements Documentation

Getting Started

jqxChart is a HTML Element which displays lightweight and powerful chart widget written 100% in javascript. it offers many advanced features and supports three different rendering technologies - svg, html5 canvas & vml. you can use jqxchart to add interactive charts to your website, build custom dashboards, or use it in your mobile applications. jqxchart offers excellent cross-browser compatibility and works well with both desktop and mobile browsers. jqxchart is being used by thousands of individual developers, small companies as well as a significant percentage of the furtune 100 companies.

Every UI element from jQWidgets toolkit needs its JavaScript files to be included in order to work properly.

The first step is to create html page and add links to the javascript files and css dependencies to your project.

The jqxChart element requires the following files:

<script type="text/javascript" src="../scripts/webcomponents-lite.min.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxcore.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxcore.elements.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxdata.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxdraw.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxchart.core.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxchart.api.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxchart.rangeselector.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxchart.annotations.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxchart.waterfall.js"></script>
The next step is to add the html element within the body of the html page.

<jqx-chart settings="elementSettings"></jqx-chart>
The last step is to initialize the element settings:
<script type="text/javascript">
JQXElements.settings["elementSettings"] =
{
title:"My Title", description:"Statistics for 2017",showLegend:true,enableAnimations:true, padding:padding, titlePadding:titlePadding, source:source, xAxis:xAxis, valueAxis:valueAxis, colorScheme:"scheme01", seriesGroups:seriesGroups, theme:"light"
}
</script>
To call a function(method), you need to pass the method name and parameters(if any) in the jqxChart's instance.
<script>
window.onload = function () {
var element = document.querySelector("jqx-chart");
element.refresh();
}
</script>
To get the result of a function after calling it, you can use the following syntax:
<script>
window.onload = function () {
var element = document.querySelector("jqx-chart");
var result = element.getInstance();
}
</script>
To set a property(option), you need to use the property name and value(s) along with the jqxChart's instance.
window.onload = function() {
document.querySelector("jqx-chart").title = 'Chart title';
}
You can also set properties of HTML Elements by using Attributes. Traditionally, attributes are used to set the initial state of an element. Properties with camelCase naming have dash-based attributes. For example: A property "dataSource" will have an attribute called "data-source".

To get a property(option), you need to use the property name along with the jqxChart's instance.
window.onload = function() {
var propertyValue = document.querySelector("jqx-chart").title;
}

Event binding can be defined in the HTML as an attribute. The syntax is: 'on-' and the event's name. Event Names with camelCase naming have dash-based attributes. The attribute's value is the event handler's name. The addEventListener function can also be used for event binding.

<script>
window.onload = function () {
var element = document.querySelector("jqx-chart");
element.addEventListener("toggle", function(event){
// Your code here
});
}
</script>

Example

<!DOCTYPE html>
<html lang="en">
<head>
<title id='Description'>Chart Custom Element</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1 maximum-scale=1 minimum-scale=1" />
<link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
<link rel="stylesheet" href="../../styles/demos.css" type="text/css" />
<script type="text/javascript" src="../../scripts/webcomponents-lite.min.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxcore.elements.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxdraw.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxchart.core.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script>
<script>
var padding = { left: 20, top: 5, right: 20, bottom: 5 };
var titlePadding = { left: 90, top: 0, right: 0, bottom: 10 };
var source = [
{ Country: 'China', Population: 1347350000, Percent: 19.18 },
{ Country: 'India', Population: 1210193422, Percent: 17.22 },
{ Country: 'USA', Population: 313912000, Percent: 4.47 },
{ Country: 'Indonesia', Population: 237641326, Percent: 3.38 },
{ Country: 'Brazil', Population: 192376496, Percent: 2.74 }
];
var xAxis =
{
dataField: 'Country',
gridLines: { visible: true },
flip: false
};
var valueAxis =
{
flip: true,
labels: {
visible: true,
formatFunction: function (value) {
return parseInt(value / 1000000);
}
}
};
var legendLayout = {
left: 500, top: 140, width: 300, height: 200, flow: 'vertical'
}
var seriesGroups =
[
{
type: 'column',
orientation: 'horizontal',
columnsGapPercent: 50,
toolTipFormatSettings: { thousandsSeparator: ',' },
series: [
{ dataField: 'Population', displayText: 'Population (millions)' }
]
}
];
JQXElements.settings["chartSettings"] = {
title:"My Title", description:"Statistics for 2017",showLegend:true,enableAnimations:true, padding:padding, titlePadding:titlePadding, source:source, xAxis:xAxis, valueAxis:valueAxis, colorScheme:"scheme01", seriesGroups:seriesGroups, theme:"light"
}
</script>
</head>
<body>
<jqx-chart settings="chartSettings"></jqx-chart>
</body>
</html>

The result of the above code is: