Zoomable Timeseries in JavaScript
Using ApexCharts with JavaScript
This Zoomable Timeseries example uses ApexCharts.js directly in JavaScript, with no wrapper component.
Install it with npm install apexcharts, then mount the chart with new ApexCharts(element, options).render().
var ts2 = new Date('14 Jan 2025').getTime()
var dates = []
for (var i = 0; i < 120; i++) {
ts2 = ts2 + 86400000
var innerArr = [ts2, dataSeries[1][i].value]
dates.push(innerArr)
}
var options = {
series: [
{
name: 'Meridian Motors',
data: dates,
},
],
chart: {
type: 'area',
stacked: false,
height: 350,
zoom: {
type: 'x',
enabled: true,
autoScaleYaxis: true,
},
toolbar: {
autoSelected: 'zoom',
},
},
dataLabels: {
enabled: false,
},
markers: {
size: 0,
},
title: {
text: 'Stock Price Movement',
align: 'left',
},
fill: {
type: 'gradient',
gradient: {
shadeIntensity: 1,
inverseColors: false,
opacityFrom: 0.5,
opacityTo: 0,
stops: [0, 90, 100],
},
},
yaxis: {
labels: {
formatter: function (val) {
return '$' + (val / 1000000).toFixed(0)
},
},
title: {
text: 'Price',
},
},
xaxis: {
type: 'datetime',
},
tooltip: {
shared: false,
y: {
formatter: function (val) {
return '$' + (val / 1000000).toFixed(0)
},
},
},
}
var chart = new ApexCharts(document.querySelector('#chart'), options)
chart.render()