JavaScript Chart Range Selector Example with zooming.
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.backgroundColor propertyshowLegend property – Determines whether to show or hide the chart series legend.padding propertycolorScheme propertyenableCrosshairs property – Enables or disables the crosshairs lines.enableAnimations property – Determines if the animations are enabled.animationDuration property – Determines the animations duration in milliseconds.xAxis property – Sets the Chart's xAxis.valueAxis propertyseriesGroups property – The seriesGroups property is used to describe all series displayed on the chart.To 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, jqxchart.rangeselector.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 () {
// prepare the data
var source =
{
datatype: "csv",
datafields: [
{ name: 'Date' },
{ name: 'Open' },
{ name: 'High' },
{ name: 'Low' },
{ name: 'Close' },
{ name: 'Volume' },
{ name: 'AdjClose' }
],
url: '../sampledata/TSLA_stockprice.csv'
};
var dataAdapter = new $.jqx.dataAdapter(source, { async: false, autoBind: true, loadError: function (xhr, status, error) { alert('Error loading "' + source.url + '" : ' + error); } });
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
var toolTipCustomFormatFn = function (value, itemIndex, serie, group, categoryValue, categoryAxis) {
return 'Index: ' + itemIndex + ", Value: " + value;
};
// prepare jqxChart settings
var settings = {
title: "Range selector with regular x-axis",
description: "In this example the range selector works with (non-date) axis",
enableAnimations: true,
showLegend: false,
animationDuration: 1500,
enableCrosshairs: true,
padding: { left: 5, top: 5, right: 20, bottom: 5 },
colorScheme: 'scheme02',
source: dataAdapter,
xAxis:
{
minValue: 175,
maxValue: 550,
flip: false,
valuesOnTicks: true,
rangeSelector: {
serieType: 'area',
padding: { /*left: 0, right: 0,*/ top: 20, bottom: 0 },
// Uncomment the line below to render the selector in a separate container
//renderTo: $('#selectorContainer'),
backgroundColor: 'white',
size: 110,
gridLines: {visible: false},
}
},
seriesGroups:
[
{
type: 'line',
toolTipFormatFunction: toolTipCustomFormatFn,
valueAxis:
{
flip: false,
title: {text: 'Value<br><br>'}
},
series: [
{ dataField: 'Close', lineWidth: 1, lineWidthSelected: 1 }
]
}
]
};
$('#chartContainer').jqxChart(settings);
});
<p>
</p><div id="chartContainer" style="width:800px; height:500px;">
</div>
<p></p>
<p>
<!-- you can optionally render the selecor in this container -->
</p><div id="selectorContainer" style="width:500px; height:100px;">
</div>
<p></p>