<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ZingSoft Demo</title>
<script nonce="undefined" src="https://cdn.zingchart.com/zingchart.min.js"></script>
<style>
.zc-body {
background: linear-gradient(45deg, #00d2ff, #3a7bd5) no-repeat;
}
.chart--container {
height: 100%;
width: 100%;
min-height: 530px;
}
.zc-ref {
display: none;
}
</style>
</head>
<body class="zc-body">
<div id="myChart">
<a href="https://www.zingchart.com/" rel="noopener" class="zc-ref">Powered by ZingChart</a>
</div>
<script>
ZC.LICENSE = ["569d52cefae586f634c54f86dc99e6a9", "b55b025e438fa8a98e32482b5f768ff5"]; // HELPER FNS
// -----------------------------
let increase;
function makeData(data) {
increase = (data.period * Math.PI) / 20;
for (let i = 0; i < data.amount; i++) {
data.values.push(180 - Math.sin(data.counter) * data.height);
data.counter += increase;
}
}
function getNextValue(data) {
increase = (data.period * Math.PI) / 20;
let value = 180 - Math.sin(data.counter) * data.height;
data.counter += increase;
return value;
}
// DEFINE CHART
// -----------------------------
// Main chart render location
let chartId = 'myChart';
// INFO
// -----------------------------
let info = {
0: {
amount: 430,
counter: 0,
values: [],
period: 0.2,
lineColor: '#28c6ff',
height: 120,
},
1: {
amount: 450,
counter: 0,
values: [],
period: 0.05,
lineColor: '#16bbff',
height: 90,
},
2: {
amount: 400,
counter: 20,
values: [],
period: 0.2,
lineColor: '#16eaff',
height: 40,
},
};
// CHART CONFIG
// -----------------------------
let chartConfig = {
type: 'line',
backgroundColor: 'transparent',
plot: {
tooltip: {
visible: false,
},
aspect: 'spline',
maxNodes: 0,
maxTrackers: 0,
marker: {
backgroundColor: '#47ccff',
borderColor: '#00AEF1',
visible: false,
},
},
plotarea: {
margin: '20px',
},
scaleY: {
values: '50:300:1',
visible: false,
},
scaleX: {
visible: false,
},
series: [{
values: info[0].values,
lineColor: info[0].lineColor,
},
{
values: info[1].values,
lineColor: info[1].lineColor,
},
{
values: info[2].values,
lineColor: info[2].lineColor,
},
],
};
// RENDER CHART
// -----------------------------
zingchart.render({
id: chartId,
data: chartConfig,
height: '560px',
width: '100%',
});
// UPDATE CHART INTERVAL
// -----------------------------
makeData(info[0]);
makeData(info[1]);
makeData(info[2]);
setInterval(function() {
let nextVal;
nextVal = getNextValue(info[0]);
info[0].values.shift();
info[0].values.push(nextVal);
nextVal = getNextValue(info[1]);
info[1].values.shift();
info[1].values.push(nextVal);
nextVal = getNextValue(info[2]);
info[2].values.shift();
info[2].values.push(nextVal);
zingchart.exec(chartId, 'setseriesdata', {
graphid: 0,
data: [{
values: info[0].values,
lineColor: info[0].lineColor,
},
{
values: info[1].values,
lineColor: info[1].lineColor,
},
{
values: info[2].values,
lineColor: info[2].lineColor,
},
],
});
}, 20);
</script>
</body>
</html>
// HELPER FNS
// -----------------------------
let increase;
function makeData(data) {
increase = (data.period * Math.PI) / 20;
for (let i = 0; i < data.amount; i++) {
data.values.push(180 - Math.sin(data.counter) * data.height);
data.counter += increase;
}
}
function getNextValue(data) {
increase = (data.period * Math.PI) / 20;
let value = 180 - Math.sin(data.counter) * data.height;
data.counter += increase;
return value;
}
// DEFINE CHART
// -----------------------------
// Main chart render location
let chartId = 'myChart';
// INFO
// -----------------------------
let info = {
0: {
amount: 430,
counter: 0,
values: [],
period: 0.2,
lineColor: '#28c6ff',
height: 120,
},
1: {
amount: 450,
counter: 0,
values: [],
period: 0.05,
lineColor: '#16bbff',
height: 90,
},
2: {
amount: 400,
counter: 20,
values: [],
period: 0.2,
lineColor: '#16eaff',
height: 40,
},
};
// CHART CONFIG
// -----------------------------
let chartConfig = {
type: 'line',
backgroundColor: 'transparent',
plot: {
tooltip: {
visible: false,
},
aspect: 'spline',
maxNodes: 0,
maxTrackers: 0,
marker: {
backgroundColor: '#47ccff',
borderColor: '#00AEF1',
visible: false,
},
},
plotarea: {
margin: '20px',
},
scaleY: {
values: '50:300:1',
visible: false,
},
scaleX: {
visible: false,
},
series: [
{
values: info[0].values,
lineColor: info[0].lineColor,
},
{
values: info[1].values,
lineColor: info[1].lineColor,
},
{
values: info[2].values,
lineColor: info[2].lineColor,
},
],
};
// RENDER CHART
// -----------------------------
zingchart.render({
id: chartId,
data: chartConfig,
height: '560px',
width: '100%',
});
// UPDATE CHART INTERVAL
// -----------------------------
makeData(info[0]);
makeData(info[1]);
makeData(info[2]);
setInterval(function () {
let nextVal;
nextVal = getNextValue(info[0]);
info[0].values.shift();
info[0].values.push(nextVal);
nextVal = getNextValue(info[1]);
info[1].values.shift();
info[1].values.push(nextVal);
nextVal = getNextValue(info[2]);
info[2].values.shift();
info[2].values.push(nextVal);
zingchart.exec(chartId, 'setseriesdata', {
graphid: 0,
data: [
{
values: info[0].values,
lineColor: info[0].lineColor,
},
{
values: info[1].values,
lineColor: info[1].lineColor,
},
{
values: info[2].values,
lineColor: info[2].lineColor,
},
],
});
}, 20);