<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ZingSoft Demo</title>
<script nonce="undefined" src="https://cdn.zingchart.com/zingchart.min.js"></script>
<script nonce="undefined" src="https://cdn.zinggrid.com/zinggrid.min.js"></script>
<style>
html,
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
.chart--container,
.grid--container {
min-height: 150px;
width: 48%;
height: 100%;
display: inline-block;
}
.zc-ref {
display: none;
}
zing-grid[loading] {
height: 696px;
}
</style>
</head>
<body>
<!-- CHART CONTAINER -->
<div id="myChart" class="chart--container">
<a class="zc-ref" href="https://www.zingchart.com/">Powered by ZingChart</a>
</div>
<div class="grid--container">
<zing-grid caption="Base Index Display" layout="row" sort>
<zg-colgroup>
<zg-column index="year"></zg-column>
<zg-column index="value" type="number"></zg-column>
<zg-column index="baseIndex" type="number"></zg-column>
</zg-colgroup>
</zing-grid>
</div>
<script>
ZC.LICENSE = ["569d52cefae586f634c54f86dc99e6a9", "b55b025e438fa8a98e32482b5f768ff5"];
ZingGrid.setLicense(['26ccbfec16b8be9ee98c7d57bee6e498']);
function formatZGValues(aValues, aLabels, nBaseValue) {
let oArr = [];
aValues.forEach((value, index) => {
oArr.push({
year: aLabels[index],
value,
baseIndex: (value / nBaseValue) * 100
})
});
return oArr;
}
function getBaseIndices(aValues, nBaseValue) {
return aValues.map(value => Math.floor((value / nBaseValue) * 100));
}
// window:load event for Javascript to run after HTML
// because this Javascript is injected into the document head
window.addEventListener('load', () => {
// Javascript code to execute after DOM content
let values = [150, 145, 142, 140, 138, 115, 112, 108, 105, 103, 99];
let labels = ['2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019'];
let baseIndexPos = 3; // 138
let baseValue = values[baseIndexPos];
let zgRef = document.querySelector('zing-grid');
// format data arrays based on inputs
let baseIndices = getBaseIndices(values, baseValue);
let zgValues = formatZGValues(values, labels, baseValue);
// set min/max globals for scales
let minValue = Math.min(...baseIndices);
let maxValue = Math.max(...baseIndices);
// full ZingChart schema can be found here:
// https://www.zingchart.com/docs/api/json-configuration/
let chartConfig = {
graphset: [{
type: 'line',
globals: {
fontSize: '14px'
},
title: {
text: 'Union Membership',
fontSize: '24px',
adjustLayout: true,
},
subtitle: {
text: `No Index`
},
legend: {
cursor: 'hand',
draggable: true
},
// plot represents general series, or plots, styling
plot: {
// hoverstate
tooltip: {
// % symbol represents a token to insert a value. Full list here:
// https://www.zingchart.com/docs/tutorials/chart-elements/zingchart-tokens/
text: '%plot-text in %kl was %v Million',
padding: '10 15',
borderRadius: '3px',
// htmlMode renders text attribute as html so
// ° is rendered
htmlMode: true
},
// animation docs here:
// https://www.zingchart.com/docs/tutorials/design-and-styling/chart-animation/#animation__effect
animation: {
effect: 'ANIMATION_SLIDE_TOP',
method: 'ANIMATION_BOUNCE_EASE_OUT',
sequence: 'ANIMATION_NO_SEQUENCE',
speed: 975
},
lineWidth: '3px',
// line node styling
marker: {
borderWidth: '0px',
size: '6px'
}
},
plotarea: {
margin: 'dynamic'
},
scaleX: {
// set scale label
label: {
text: 'Years'
},
// convert text on scale indices
labels,
},
scaleY: {
// scale label with unicode character
label: {
text: 'Millions Employed'
},
format: '%vM'
},
series: [{
text: 'Union Employment',
// plot values
values,
lineColor: '#9c27b0',
marker: {
backgroundColor: '#ba68c8'
}
}]
},
{
type: 'line',
globals: {
fontSize: '14px'
},
title: {
text: 'Union Membership',
fontSize: '24px',
adjustLayout: true,
},
subtitle: {
text: `Index: ${labels[baseIndexPos]}=${values[baseIndexPos]}`
},
legend: {
cursor: 'hand',
draggable: true
},
// plot represents general series, or plots, styling
plot: {
// hoverstate
tooltip: {
// % symbol represents a token to insert a value. Full list here:
// https://www.zingchart.com/docs/tutorials/chart-elements/zingchart-tokens/
text: '%plot-text in %kl was %v Million',
padding: '10 15',
borderRadius: '3px',
// htmlMode renders text attribute as html so
// ° is rendered
htmlMode: true
},
// animation docs here:
// https://www.zingchart.com/docs/tutorials/design-and-styling/chart-animation/#animation__effect
animation: {
effect: 'ANIMATION_SLIDE_TOP',
method: 'ANIMATION_BOUNCE_EASE_OUT',
sequence: 'ANIMATION_NO_SEQUENCE',
speed: 975
},
lineWidth: '3px',
// line node styling
marker: {
borderWidth: '0px',
size: '6px'
}
},
plotarea: {
margin: 'dynamic'
},
scaleX: {
// set scale label
label: {
text: 'Years'
},
// convert text on scale indices
labels,
},
scaleY: {
minValue,
maxValue,
// scale label with unicode character
label: {
text: 'Index'
},
markers: [{
type: 'line',
range: [100],
lineWidth: 2,
label: {
text: 'Base Index'
}
}]
},
series: [{
text: 'Union Employment',
// plot values
values: baseIndices,
lineColor: '#9c27b0',
marker: {
backgroundColor: '#ba68c8'
}
}]
},
],
};
// render grid
zgRef.setData(zgValues);
// render chart with width and height to
// fill the parent container CSS dimensions
zingchart.render({
id: 'myChart',
data: chartConfig,
height: '100%',
width: '100%'
});
});
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ZingSoft Demo</title>
<script src="https://cdn.zingchart.com/zingchart.min.js"></script>
<script src="https://cdn.zinggrid.com/zinggrid.min.js"></script>
</head>
<body>
<!-- CHART CONTAINER -->
<div id="myChart" class="chart--container">
<a class="zc-ref" href="https://www.zingchart.com/">Powered by ZingChart</a>
</div>
<div class="grid--container">
<zing-grid caption="Base Index Display" layout="row" sort>
<zg-colgroup>
<zg-column index="year"></zg-column>
<zg-column index="value" type="number"></zg-column>
<zg-column index="baseIndex" type="number"></zg-column>
</zg-colgroup>
</zing-grid>
</div>
</body>
</html>
html,
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
.chart--container,
.grid--container {
min-height: 150px;
width: 48%;
height: 100%;
display: inline-block;
}
.zc-ref {
display: none;
}
function formatZGValues(aValues, aLabels, nBaseValue) {
let oArr = [];
aValues.forEach((value, index) => {
oArr.push({
year: aLabels[index],
value,
baseIndex: (value / nBaseValue) * 100
})
});
return oArr;
}
function getBaseIndices(aValues, nBaseValue) {
return aValues.map(value => Math.floor((value / nBaseValue) * 100));
}
// window:load event for Javascript to run after HTML
// because this Javascript is injected into the document head
window.addEventListener('load', () => {
// Javascript code to execute after DOM content
let values = [150, 145, 142, 140, 138, 115, 112, 108, 105, 103, 99];
let labels = ['2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019'];
let baseIndexPos = 3; // 138
let baseValue = values[baseIndexPos];
let zgRef = document.querySelector('zing-grid');
// format data arrays based on inputs
let baseIndices = getBaseIndices(values, baseValue);
let zgValues = formatZGValues(values, labels, baseValue);
// set min/max globals for scales
let minValue = Math.min(...baseIndices);
let maxValue = Math.max(...baseIndices);
// full ZingChart schema can be found here:
// https://www.zingchart.com/docs/api/json-configuration/
let chartConfig = {
graphset: [{
type: 'line',
globals: {
fontSize: '14px'
},
title: {
text: 'Union Membership',
fontSize: '24px',
adjustLayout: true,
},
subtitle: {
text: `No Index`
},
legend: {
cursor: 'hand',
draggable: true
},
// plot represents general series, or plots, styling
plot: {
// hoverstate
tooltip: {
// % symbol represents a token to insert a value. Full list here:
// https://www.zingchart.com/docs/tutorials/chart-elements/zingchart-tokens/
text: '%plot-text in %kl was %v Million',
padding: '10 15',
borderRadius: '3px',
// htmlMode renders text attribute as html so
// ° is rendered
htmlMode: true
},
// animation docs here:
// https://www.zingchart.com/docs/tutorials/design-and-styling/chart-animation/#animation__effect
animation: {
effect: 'ANIMATION_SLIDE_TOP',
method: 'ANIMATION_BOUNCE_EASE_OUT',
sequence: 'ANIMATION_NO_SEQUENCE',
speed: 975
},
lineWidth: '3px',
// line node styling
marker: {
borderWidth: '0px',
size: '6px'
}
},
plotarea: {
margin: 'dynamic'
},
scaleX: {
// set scale label
label: {
text: 'Years'
},
// convert text on scale indices
labels,
},
scaleY: {
// scale label with unicode character
label: {
text: 'Millions Employed'
},
format: '%vM'
},
series: [{
text: 'Union Employment',
// plot values
values,
lineColor: '#9c27b0',
marker: {
backgroundColor: '#ba68c8'
}
}]
},
{
type: 'line',
globals: {
fontSize: '14px'
},
title: {
text: 'Union Membership',
fontSize: '24px',
adjustLayout: true,
},
subtitle: {
text: `Index: ${labels[baseIndexPos]}=${values[baseIndexPos]}`
},
legend: {
cursor: 'hand',
draggable: true
},
// plot represents general series, or plots, styling
plot: {
// hoverstate
tooltip: {
// % symbol represents a token to insert a value. Full list here:
// https://www.zingchart.com/docs/tutorials/chart-elements/zingchart-tokens/
text: '%plot-text in %kl was %v Million',
padding: '10 15',
borderRadius: '3px',
// htmlMode renders text attribute as html so
// ° is rendered
htmlMode: true
},
// animation docs here:
// https://www.zingchart.com/docs/tutorials/design-and-styling/chart-animation/#animation__effect
animation: {
effect: 'ANIMATION_SLIDE_TOP',
method: 'ANIMATION_BOUNCE_EASE_OUT',
sequence: 'ANIMATION_NO_SEQUENCE',
speed: 975
},
lineWidth: '3px',
// line node styling
marker: {
borderWidth: '0px',
size: '6px'
}
},
plotarea: {
margin: 'dynamic'
},
scaleX: {
// set scale label
label: {
text: 'Years'
},
// convert text on scale indices
labels,
},
scaleY: {
minValue,
maxValue,
// scale label with unicode character
label: {
text: 'Index'
},
markers: [{
type: 'line',
range: [100],
lineWidth: 2,
label: {
text: 'Base Index'
}
}]
},
series: [{
text: 'Union Employment',
// plot values
values: baseIndices,
lineColor: '#9c27b0',
marker: {
backgroundColor: '#ba68c8'
}
}]
},
],
};
// render grid
zgRef.setData(zgValues);
// render chart with width and height to
// fill the parent container CSS dimensions
zingchart.render({
id: 'myChart',
data: chartConfig,
height: '100%',
width: '100%'
});
});