我有一个JSChart的代码。我需要更改图表的颜色,而不是背景颜色,而是图形的颜色。我可以使用JS进行更改,但是我需要使用CSS进行更改,因为我有交换颜色主题按钮。因此,除了使用JS之外,我还需要使用CSS来完成它。
我尝试过在CSS中收到发送的Linechart,收到的Linechart,Linechart.sent,Linechart。
Below is the snippet which has JS and the HTML
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
title: {
text: "Daily Email Analysis"
},
axisX: {
valueFormatString: "DDD",
minimum: new Date(2017, 1, 5, 23),
maximum: new Date(2017, 1, 12, 1)
},
axisY: {
title: "Number of Messages"
},
legend: {
verticalAlign: "top",
horizontalAlign: "right",
dockInsidePlotArea: true
},
toolTip: {
shared: true
},
data: [{
name: "Received",
showInLegend: true,
legendMarkerType: "square",
type: "area",
color: "#3bff00",
markerSize: 0,
dataPoints: [
{ x: new Date(2017, 1, 6), y: 220 },
{ x: new Date(2017, 1, 7), y: 120 },
{ x: new Date(2017, 1, 8), y: 144 },
{ x: new Date(2017, 1, 9), y: 162 },
{ x: new Date(2017, 1, 10), y: 129 },
{ x: new Date(2017, 1, 11), y: 109 },
{ x: new Date(2017, 1, 12), y: 149 }
]
},
{
name: "Sent",
showInLegend: true,
legendMarkerType: "square",
type: "area",
color: "rgba(0, 255, 216,0.6)",
markerSize: 0,
dataPoints: [
{ x: new Date(2017, 1, 6), y: 42 },
{ x: new Date(2017, 1, 7), y: 134 },
{ x: new Date(2017, 1, 8), y: 79 },
{ x: new Date(2017, 1, 9), y: 102 },
{ x: new Date(2017, 1, 10), y: 183},
{ x: new Date(2017, 1, 11), y: 100 },
{ x: new Date(2017, 1, 12), y: 120 }
]
}]
});
chart.render();
}
<canvas id="lineChart"></canvas>
<div id="chartContainer" style="height: 300px; width: 800px;padding-left:10%"></div>
由于我将使用多个样式表,因此如果我要从CSS更改图形的颜色主题,那将非常有帮助