Custom Elements Documentation

Getting Started

jqxKnob is a HTML Element which displays a graph with round shape which displays a draggable indicator within a range of values. knob can be used in a table or matrix to show the relative value of a field in a range of values in the data region, for example, as a kpi. it supports html5, svg and vml rendering.

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 jqxKnob 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/jqxknob.js"></script>
The next step is to add the html element within the body of the html page.

<jqx-knob settings="elementSettings"></jqx-knob>
The last step is to initialize the element settings:
<script type="text/javascript">
JQXElements.settings["elementSettings"] =
{
value:60,min:0,max:100,startAngle:120,endAngle:480,snapToStep:true, rotation:"clockwise", pointer:pointer, progressBar:progressBar, marks:marks, labels:labels,allowValueChangeOnClick:true, theme:"light"
}
</script>
To call a function(method), you need to pass the method name and parameters(if any) in the jqxKnob's instance.
<script>
window.onload = function () {
var element = document.querySelector("jqx-knob");
element.destroy();
}
</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-knob");
var result = element.val();
}
</script>
To set a property(option), you need to use the property name and value(s) along with the jqxKnob's instance.
window.onload = function() {
document.querySelector("jqx-knob").allowValueChangeOnClick = true;
}
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 jqxKnob's instance.
window.onload = function() {
var propertyValue = document.querySelector("jqx-knob").allowValueChangeOnClick;
}

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-knob");
element.addEventListener("change", function(event){
// Your code here
});
}
</script>

Example

<!DOCTYPE html>
<html lang="en">
<head>
<title id='Description'>Knob 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/jqxdraw.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxknob.js"></script>
<script>
var labels = {
offset: '88%',
step: 10,
visible: true
}
var marks = {
colorRemaining: { color: '#373636', border: '#373636' },
colorProgress: { color: '#373636', border: '#373636' },
type: 'line',
offset: '71%',
thickness: 1,
size: '6%',
majorSize: '9%',
majorInterval: 10,
minorInterval: 2
}
var progressBar = {
size: '70%',
offset: '0%',
background: {
stroke: '#373636', strokeWidth: 1, fill: { color: '#a7a7a7', gradientType: "linear", gradientStops: [[0, 1], [50, 0.5], [100, 1]] }
}
}
var pointer = {
type: 'circle', style: { fill: { color: '#a4a3a3', gradientType: "linear", gradientStops: [[0, 0.5], [50, 0.6], [100, 1]] }, stroke: '#333' },
size: '10%', offset: '50%'
}
JQXElements.settings["knobSettings"] =
{
value:60,min:0,max:100,startAngle:120,endAngle:480,snapToStep:true, rotation:"clockwise", pointer:pointer, progressBar:progressBar, marks:marks, labels:labels,allowValueChangeOnClick:true, theme:"light"
}
</script>
</head>
<body>
<jqx-knob settings="knobSettings"></jqx-knob>
</body>
</html>

The result of the above code is: