JavaScript Chart Line Series displaying data from separate arrays.
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.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, jqxdraw.js, jqxchart.core.js, jqxdata.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 days = [
{ Day: 'Monday' },
{ Day: 'Tuesday' },
{ Day: 'Wednesday' },
{ Day: 'Thursday' },
{ Day: 'Friday' },
{ Day: 'Saturday' },
{ Day: 'Sunday' }
];
var Keith = [
{ Minutes: 30 },
{ Minutes: 25 },
{ Minutes: 30 },
{ Minutes: 35 },
{ Minutes: 20 },
{ Minutes: 30 },
{ Minutes: 60 }
];
var Erica = [
{ Minutes: 15 },
{ Minutes: 25 },
{ Minutes: 20 },
{ Minutes: 25 },
{ Minutes: 20 },
{ Minutes: 20 },
{ Minutes: 45 }
];
var George = [
{ Minutes: 25 },
{ Minutes: 30 },
{ Minutes: 25 },
{ Minutes: 45 },
{ Minutes: 25 },
{ Minutes: 30 },
{ Minutes: 90 }
];
// prepare jqxChart settings
var settings = {
title: "Fitness & exercise weekly scorecard",
description: "Time spent in vigorous exercise",
enableAnimations: true,
showLegend: true,
padding: { left: 5, top: 5, right: 40, bottom: 5 },
titlePadding: { left: 90, top: 0, right: 0, bottom: 10 },
source: days,
source: days,
xAxis:
{
dataField: 'Day',
gridLines: { visible: true }
},
colorScheme: 'scheme02',
valueAxis:
{
visible: true,
title: { text: 'Time in minutes' }
},
seriesGroups:
[
{
type: 'stackedline',
source: Keith,
series: [
{ dataField: 'Minutes', displayText: 'Keith' }
]
},
{
type: 'stackedline',
source: Erica,
series: [
{ dataField: 'Minutes', displayText: 'Erica' }
]
},
{
type: 'stackedline',
source: George,
series: [
{ dataField: 'Minutes', displayText: 'George' }
]
}
]
};
// setup the chart
$('#jqxChart').jqxChart(settings);
});
<div style="height: 600px; width: 682px;">
<div id="host" style="margin: 0 auto; width: 850px; height: 400px;">
<div id="jqxChart" style="width: 850px; height: 400px; position: relative; left: 0px; top: 0px;">
</div>
</div>
</div>