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:
The next step is to add the html element within the body of the html page.<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 last step is to initialize the element settings:<jqx-knob settings="elementSettings"></jqx-knob>
To call a function(method), you need to pass the method name and parameters(if any) in the jqxKnob's instance.<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 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");
element.destroy();
}
</script>
To set a property(option), you need to use the property name and value(s) along with the jqxKnob's instance.<script>
window.onload = function () {
var element = document.querySelector("jqx-knob");
var result = element.val();
}
</script>
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".window.onload = function() {
document.querySelector("jqx-knob").allowValueChangeOnClick = true;
}
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>
<!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>