Apexcharts example code
In this article, we'll show you a apexcharts example code. Apexcharts a popular JavaScript library renowned for its flexibility and ease of use. ApexCharts is a JavaScript library used for creating interactive and visually appealing charts and graphs on web applications. It offers a wide range of chart types, including line, bar, area, pie, and scatter plots.
We'll explore how to create a compelling combination of line and bar charts, specifically showcasing the number of clicks within 3-hour intervals over a defined period.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bar chart with Line</title>
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
<style>
.arrow_box {
border: 2px solid #D3D3D3;
border-radius: 6px;
font-size: 18px;
}
.timeslot {
padding: 10px 15px;
margin-bottom: 10px;
border-bottom: 1px solid #D3D3D3;
background-color: #D3D3D3;
opacity: 0.6;
}
.clicksCount {
padding: 10px 15px;
background-color: #ffffff;
}
</style>
</head>
<body>
<div id="chart"></div>
<script>
let options = {
series: [{
name: 'click',
type: 'bar',
data: [23, 42, 35, 27, 43, 22, 17]
},
{
name: 'click',
type: 'line',
data: [23, 42, 35, 27, 43, 22, 17]
}],
chart: {
height: 350,
type: 'bar',
width: '1000',
toolbar: {
show: false
},
},
stroke: {
curve: 'smooth',
width: [0, 5]
},
dataLabels: {
enabled: false
},
grid: {
show: false,
},
colors: ['#000000' ],
fill : {
colors : ['transparent', '#202020'],
},
markers : {
size: [0, 6],
hover : {
size : [6],
}
},
xaxis: {
categories: [
'0:00', '03:00', '06:00', '09:00', '12:00', '15:00', '18:00', '21:00'
],
labels: {
offsetX: -20
},
title: {
offsetY: 100
},
axisTicks: {
show: false,
},
tooltip : {
enabled : false,
},
},
yaxis: {
title: {
text: ''
}
},
plotOptions: {
bar: {
horizontal: false,
columnWidth: '100%',
endingShape: 'flat' ,
fill: {
colors: ['transparent']
}
},
line: {
markers: {
showOnHover: true
}
}
},
legend : {
show :false
},
tooltip: {
custom: ({series, seriesIndex, dataPointIndex, w}) => {
return `<div class="arrow_box"><div class="timeslot"><strong>${w.globals.labels[dataPointIndex]+'am'} - ${w.globals.labels[dataPointIndex+1] + 'am' }</strong></div><div class="clicksCount"> <span class="marker"><svg width="10" height="10" viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg"><circle cx="5" cy="5" r="3" fill="black" stroke="black" stroke-width="5" /></svg></span> Clicks <strong style="float:right">${series[seriesIndex][dataPointIndex]}</strong></div>`;
}
}
};
var chart = new ApexCharts(document.querySelector("#chart"), options);
chart.render();
</script>
</body>
</html>
This above code snippet integrates the ApexCharts library via a CDN for easy implementation. It features a column chart displayed within a div element with the ID "chart". The chart is configured using a set of options defined in the JavaScript section. These options include settings for chart appearance, data series, axis labels, and tooltips. The chart is initialized and rendered using the ApexCharts constructor and the render method, respectively, bringing the visual representation of data to life effortlessly.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Javascript
- How to pass array as arguments to function in javascript
- How to Set data to localstorage in javascript
- Uncaught TypeError: Illegal invocation
- Concat variable with string in javascript
- Deault order of record in datatable
- How to use JavaScript to search for items in a list
- Generate 6 digit random number in javascript
- How to remove duplicate values from array in javascript
- Javascript get only 10 characters from string
- How to push string in an array in Javascript
- How to get data from localstorage in javascript
- ReferenceError: Cannot access 'myFunction' before initialization
- How to validate input type file size in javascript
- How to add a property to object with condition in javascript
- Javascript set timeout function with example code
- Uncaught TypeError: Assignment to constant variable
- How to set href value of anchor tag in javascript
- How to get file extension using javascript/jquery
- How to show and hide placeholder text
- ReferenceError: $ is not defined
- How to switch between Dark Mode and Light Mode based on cookie in Javascript
- Copy one array to another in javascript
- How to display an image in Javascript onclick
- On click enter redirect to another URL with parameters in javascript
- Animating numbers counting Javascript