|
Select Series 1 Symbol: |
Select Series 2 Symbol: |
JavaScript Chart Scatter Series 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 propertyenableAnimations 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 methodupdate 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, jqxbuttons.js, jqxlistbox.js, jqxscrollbar.js, jqxdropdownlist.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 chart data as an array
var sampleData = [
{ City: 'New York', SalesQ1: 330500, SalesQ2: 210500, YoYGrowth: 1.05 },
{ City: 'London', SalesQ1: 120000, SalesQ2: 169000, YoYGrowth: 1.15 },
{ City: 'Paris', SalesQ1: 205000, SalesQ2: 275500, YoYGrowth: 1.45 },
{ City: 'Tokyo', SalesQ1: 187000, SalesQ2: 130100, YoYGrowth: 0.45 },
{ City: 'Berlin', SalesQ1: 187000, SalesQ2: 113000, YoYGrowth: 1.65 },
{ City: 'San Francisco', SalesQ1: 142000, SalesQ2: 102000, YoYGrowth: 1.25 },
{ City: 'Chicago', SalesQ1: 171000, SalesQ2: 124000, YoYGrowth: 0.75 }
];
// prepare jqxChart settings
var settings = {
title: "Sales by City in Q1 & Q2",
description: "",
enableAnimations: true,
showLegend: true,
padding: { left: 5, top: 5, right: 5, bottom: 5 },
titlePadding: { left: 90, top: 0, right: 0, bottom: 10 },
source: sampleData,
colorScheme: 'scheme01',
xAxis:
{
dataField: 'City',
valuesOnTicks: false
},
valueAxis:
{
minValue: 50000,
maxValue: 350000,
unitInterval: 50000,
title: {text: 'Sales ($)<br>'},
labels: {
formatSettings: { prefix: '$', thousandsSeparator: ',' },
horizontalAlignment: 'right'
}
},
seriesGroups:
[
{
type: 'scatter',
series: [
{ dataField: 'SalesQ1', symbolSize: 20, symbolType: 'circle', displayText: 'Sales in Q1'},
{ dataField: 'SalesQ2', symbolSize: 20, symbolType: 'diamond', displayText: 'Sales in Q2'}
]
}
]
};
// setup the chart
$('#chartContainer').jqxChart(settings);
var chart = $('#chartContainer').jqxChart('getInstance');
// symbol selection drop down
var symbolsList = ["circle", "diamond", "square", "triangle_up", "triangle_down", "triangle_left", "triangle_right"];
$("#dropDownSerie1Symbol").jqxDropDownList({ source: symbolsList, selectedIndex: 2, width: '200', height: '25', dropDownHeight: 100 });
$('#dropDownSerie1Symbol').on('change', function (event) {
var value = event.args.item.value;
chart.seriesGroups[0].series[0].symbolType = value;
chart.update();
});
$("#dropDownSerie2Symbol").jqxDropDownList({ source: symbolsList, selectedIndex: 1, width: '200', height: '25', dropDownHeight: 100 });
$('#dropDownSerie2Symbol').on('change', function (event) {
var value = event.args.item.value;
chart.seriesGroups[0].series[1].symbolType = value;
chart.update();
});
});
<div id="chartContainer" style="width: 850px; height: 500px">
</div>
<table style="width: 550px">
<tbody><tr>
<td>
<p style="font-family: Verdana; font-size: 12px;">Select Serie 1 Symbol:
</p>
<div id="dropDownSerie1Symbol">
</div>
</td>
<td>
<p style="font-family: Verdana; font-size: 12px;">Select Serie 2 Symbol:
</p>
<div id="dropDownSerie2Symbol">
</div>
</td>
</tr>
</tbody></table>