i have a simple js, html file, im using ApexCharts and want to handle the positive and negative parts of chart.
3 things about it:
- markers style (handled already)
- line color (handled already)
- the background gradient below the line (problem)
is there any way to add a background to the line type chart below the line?
<div id="chart"></div>
<script src="exp.js"></script>
const dataPoints = [-10, 3, -5, -18, -10, 12, 8]
const discreteMarkers = dataPoints.map((value, index) => {
return {
shape: "circle",
size: 4,
seriesIndex: 0,
dataPointIndex: index,
fillColor: "#ffffff",
strokeColor: value >= 0 ? "#157446" : "#C13446",
strokeWidth: 1,
};
});
var options = {
chart: {
height: 380,
type: "line",
foreColor: '#aaa',
zoom: {
type: 'x',
enabled: true,
autoScaleYaxis: true
},
},
series: [
{
name: "Series 1",
data: dataPoints
}
],
stroke: {
width: 5,
curve: "monotoneCubic"
},
plotOptions: {
line: {
colors: {
threshold: 0,
colorAboveThreshold: '#157446',
colorBelowThreshold: '#C13446',
},
},
},
markers: {
discrete: discreteMarkers
},
grid: {
borderColor: '#6D6D6D',
strokeDashArray: 3,
},
xaxis: {
categories: [
"01 Jan",
"02 Jan",
"03 Jan",
"04 Jan",
"05 Jan",
"06 Jan",
"07 Jan"
]
},
stroke: {
curve: 'smooth',
width: 2
},
};
var chart = new ApexCharts(document.querySelector("#chart"), options);
chart.render();
here is a link to check output.
https://codepen.io/amirdoosti/pen/RNbQWPK
2
Answers
You can use the
fill
property to handle that! I try that solution in your codepen and this is the result (to achieve it I remove plotOptions)What you are trying to achieve is an "area" chart type, not "line" chart.
Try changing your script to this:
That would render this: