|
|
||||||||||||||||||||||||
JavaScript Chart unit intervals, grid lines, tick marks and label steps example.
A live JavaScript/jQuery example of jqxChart, the jQWidgets Chart component, with its complete source code below. It is one of 92 jqxChart demos for jQuery.
title property – Sets or gets the jqxChart title.description property – Sets or gets the jqxChart description.source property – Sets the chart's data source.showLegend property – Determines whether to show or hide the chart series legend.padding propertytitlePadding propertycolorScheme propertyenableCrosshairs property – Enables or disables the crosshairs lines.enableAnimations property – Determines if the animations are enabled.xAxis property – Sets the Chart's xAxis.valueAxis propertyseriesGroups property – The seriesGroups property is used to describe all series displayed on the chart.getInstance methodrefresh methodTo run it in your own page, load jqx.base.css, a theme and the library files below from npm (npm install jqwidgets-scripts) or the jsDelivr CDN, then add the markup and the script. jQuery is not required: jqxcore.js provides $. Getting started with jqxChart shows the setup step by step.
The page loads jqx.base.css, a theme and these library files: jqxcore.js, jqxdata.js, jqxdraw.js, jqxchart.core.js, jqxnumberinput.js, jqxbuttons.js, jqxcheckbox.js.
It also loads helper scripts of this demo site, which are not part of the library: demos.js (getWidth() and other layout helpers).
$(document).ready(function () {
var data = [12, 3, 16, 12, 24, 15, 17, 9, 31, 25, 15, 5, 8, 19, 23, 15, 31, 26, 11, 19, 5, 1, 8, 18, 12, 3, 16, 12, 24, 15, 17, 9, 31, 25, 15, 5, 8, 19, 23, 15, 31, 26, 11, 19, 5, 1, 8, 18, 5, 12, 11];
// prepare jqxChart settings
var settings = {
title: "jqxChart unit interval and steps example",
description: " ",
enableAnimations: false,
showLegend: true,
enableCrosshairs: false,
padding: { left: 10, top: 5, right: 10, bottom: 5 },
titlePadding: { left: 90, top: 0, right: 0, bottom: 10 },
source: data,
xAxis:
{
unitInterval: 1,
gridLines: { step: 1 },
tickMarks: { step: 1 },
labels: { step: 2 }
},
valueAxis:
{
title: { text: 'Value<br>' },
unitInterval: 5,
gridLines: { step: 1 },
tickMarks: { step: 1 },
labels: { step: 1 },
minValue: 0
},
colorScheme: 'scheme05',
seriesGroups:
[
{
type: 'line',
series:
[
{ displayText: 'value', opacity: 0.7 }
]
}
]
};
// setup the chart
$('#chartContainer').jqxChart(settings);
var chartInstance = $('#chartContainer').jqxChart('getInstance');
// xAxis settigns inputs
$("#inputXAxisUnitInterval").jqxNumberInput({ width: '50px', height: '25px', inputMode: 'simple', min: 1, max: 10, value: 1, decimalDigits: 0, digits: 2, spinButtons: true })
.on('valueChanged', function (event) {
var value = event.args.value;
chartInstance.xAxis.unitInterval = parseInt(value);
chartInstance.refresh();
});
$("#inputXAxisLabelsStep").jqxNumberInput({ width: '50px', height: '25px', inputMode: 'simple', min: 1, max: 10, value: 2, decimalDigits: 0, digits: 2, spinButtons: true })
.on('valueChanged', function (event) {
var value = event.args.value;
chartInstance.xAxis.labels.step = parseInt(value);
chartInstance.refresh();
});
$("#inputXAxisTickMarksStep").jqxNumberInput({ width: '50px', height: '25px', inputMode: 'simple', min: 1, max: 10, value: 1, decimalDigits: 0, digits: 2, spinButtons: true })
.on('valueChanged', function (event) {
var value = event.args.value;
chartInstance.xAxis.tickMarks.step = parseInt(value);
chartInstance.refresh();
});
$("#inputXAxisGridLinesStep").jqxNumberInput({ width: '50px', height: '25px', inputMode: 'simple', min: 1, max: 10, value: 1, decimalDigits: 0, digits: 2, spinButtons: true })
.on('valueChanged', function (event) {
var value = event.args.value;
chartInstance.xAxis.gridLines.step = parseInt(value);
chartInstance.refresh();
});
$("#btnValuesBetweenTicks").jqxCheckBox({ width: 120, height: 25, hasThreeStates: false, checked: false });
$("#btnValuesBetweenTicks").on('change', function (event) {
chartInstance.xAxis.valuesOnTicks = !event.args.checked;
chartInstance.refresh();
});
// valueAxis settigns inputs
$("#inputValueAxisUnitInterval").jqxNumberInput({ width: '50px', height: '25px', inputMode: 'simple', min: 1, max: 10, value: 5, decimalDigits: 0, digits: 2, spinButtons: true })
.on('valueChanged', function (event) {
var value = event.args.value;
chartInstance.valueAxis.unitInterval = parseInt(value);
chartInstance.refresh();
});
$("#inputValueAxisLabelsStep").jqxNumberInput({ width: '50px', height: '25px', inputMode: 'simple', min: 1, max: 10, value: 1, decimalDigits: 0, digits: 2, spinButtons: true })
.on('valueChanged', function (event) {
var value = event.args.value;
chartInstance.valueAxis.labels.step = parseInt(value);
chartInstance.refresh();
});
$("#inputValueAxisTickMarksStep").jqxNumberInput({ width: '50px', height: '25px', inputMode: 'simple', min: 1, max: 10, value: 1, decimalDigits: 0, digits: 2, spinButtons: true })
.on('valueChanged', function (event) {
var value = event.args.value;
chartInstance.valueAxis.tickMarks.step = parseInt(value);
chartInstance.refresh();
});
$("#inputValueAxisGridLinesStep").jqxNumberInput({ width: '50px', height: '25px', inputMode: 'simple', min: 1, max: 10, value: 1, decimalDigits: 0, digits: 2, spinButtons: true })
.on('valueChanged', function (event) {
var value = event.args.value;
chartInstance.valueAxis.gridLines.step = parseInt(value);
chartInstance.refresh();
});
$("#btnValueAxisValuesBetweenTicks").jqxCheckBox({ height: 25, hasThreeStates: false, checked: false });
$("#btnValueAxisValuesBetweenTicks").on('change', function (event) {
chartInstance.valueAxis.valuesOnTicks = !event.args.checked;
chartInstance.refresh();
});
});
<div id="chartContainer" style="width:850px; height:500px">
</div>
<table>
<tbody><tr>
<td>
<table>
<tbody><tr style="height: 50px"><td colspan="2"><b>xAxis settings:</b></td></tr>
<tr>
<td>Labels step</td><td><div id="inputXAxisLabelsStep"></div></td>
</tr>
<tr>
<td>Grid lines step</td><td><div id="inputXAxisGridLinesStep"></div></td>
</tr>
<tr>
<td>Tick marks step</td><td><div id="inputXAxisTickMarksStep"></div></td>
</tr>
<tr>
<td>Unit interval</td><td><div id="inputXAxisUnitInterval"></div></td>
</tr>
<tr style="height: 40px">
<td colspan="2"><div id="btnValuesBetweenTicks">Values between ticks</div></td>
</tr>
</tbody></table>
</td>
<td>
<table style="padding-left: 100px;">
<tbody><tr style="height: 50px"><td colspan="2"><b>valueAxis settings:</b></td></tr>
<tr>
<td>Labels step</td><td><div id="inputValueAxisLabelsStep"></div></td>
</tr>
<tr>
<td>Grid lines step</td><td><div id="inputValueAxisGridLinesStep"></div></td>
</tr>
<tr>
<td>Tick marks step</td><td><div id="inputValueAxisTickMarksStep"></div></td>
</tr>
<tr>
<td>Unit interval</td><td><div id="inputValueAxisUnitInterval"></div></td>
</tr>
<tr style="height: 40px">
<td colspan="2"><div id="btnValueAxisValuesBetweenTicks">Values between ticks</div></td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>