Skip to content

Instantly share code, notes, and snippets.

@Miliks
Last active September 11, 2019 15:54
Show Gist options
  • Save Miliks/eec89c68c38c36b493017d8c6f933731 to your computer and use it in GitHub Desktop.
Save Miliks/eec89c68c38c36b493017d8c6f933731 to your computer and use it in GitHub Desktop.
Creating your first ApexChart
<div id="chart">
</div>
var arr = new Array();
var data = [];
arr.push({x:5,y:10});
arr.push({x:10,y:20});
arr.push({x:15,y:20});
arr.push({x:25,y:20});
function getCoordinates()
{
var i= 0;
for (var i = 0; i < arr.length; i+=1) {
var x = arr[i];
var y = arr[i+1];
console.log(arr[i]);
}
data.push({ x, y
});
}
var options = {
chart: {
height: 350,
type: 'line',
animations: {
enabled: true,
easing: 'linear',
},
toolbar: {
show: false
},
zoom: {
enabled: false
}
},
dataLabels: {
enabled: false
},
stroke: {
curve: 'smooth'
},
series: [{
data: data
}],
title: {
text: 'Dynamic Updating Chart',
align: 'left'
},
markers: {
size: 2
},
xaxis: {
min:0,
max: 100,
},
yaxis: {
min:0,
max: 100
},
legend: {
show: false
},
}
var chart = new ApexCharts(
document.querySelector("#chart"),
options
);
chart.render();
window.setInterval(function () {
getCoordinates()
chart.updateSeries([{
data: data
}])
}, 60000)
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
@import url(https://fonts.googleapis.com/css?family=Roboto);
body {
font-family: Roboto, sans-serif;
}
#chart {
max-width: 650px;
margin: 35px auto;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment