Fre*_*ddy 2 javascript amcharts amcharts4
我正在尝试更改我正在使用的图形的网格线(和边框)颜色。我看过文档,但只找到了更改fill. 看不到任何有关实际线路的信息。
演示:
var chart = am4core.create("dataChart", am4charts.XYChart);
chart.data = [{
"xValue": "Q1",
"yValue": 3
}, {
"xValue": "Q2",
"yValue": 4
}, {
"xValue": "Q3",
"yValue": 7
}, {
"xValue": "Q4",
"yValue": 2
}, {
"xValue": "Q5",
"yValue": 9
}];
/* Create axes */
var theXAxis = chart.xAxes.push(new am4charts.CategoryAxis());
theXAxis.dataFields.category = "xValue";
theXAxis.renderer.minGridDistance = 30;
/* Create value axis */
var theYAxis = chart.yAxes.push(new am4charts.ValueAxis());
theYAxis.renderer.labels.template.disabled = true;
/* Create series */
var series1 = chart.series.push(new am4charts.LineSeries());
series1.dataFields.valueY = "yValue";
series1.dataFields.categoryX = "xValue";
series1.bullets.push(new am4charts.CircleBullet());
series1.tooltipText = "{valueY} / 10";
series1.fill = "#2c3e96";
series1.fillOpacity = .3;
series1.stroke = "#4967fa";
/* Create a cursor */
chart.cursor = new am4charts.XYCursor();Run Code Online (Sandbox Code Playgroud)
body{
background: grey;
}Run Code Online (Sandbox Code Playgroud)
<script src="https://www.amcharts.com/lib/4/core.js"></script>
<script src="https://www.amcharts.com/lib/4/charts.js"></script>
<script src="https://www.amcharts.com/lib/4/themes/animated.js"></script>
<div id="dataChart"></div>Run Code Online (Sandbox Code Playgroud)
我指的是那些深灰色网格线。
有什么办法可以改变这种情况吗?
在轴渲染器中,您可以访问轴的许多组件,例如标签、刻度和 ,包括网格线。您可以通过修改网格模板来更改网格线颜色。
theXAxis.renderer.grid.template.stroke = "#ff0000";
theYAxis.renderer.grid.template.stroke = "#ff0000";
Run Code Online (Sandbox Code Playgroud)
这也在网格、标签和刻度部分下的文档中的轴概述中进行了演示。
至于边框,您需要在相关容器的背景(在本例中为 plotContainer)上设置笔触。您可以在此处找到有关使用容器的更多信息
chart.plotContainer.background.stroke = "#ff0000";
Run Code Online (Sandbox Code Playgroud)
theXAxis.renderer.grid.template.stroke = "#ff0000";
theYAxis.renderer.grid.template.stroke = "#ff0000";
Run Code Online (Sandbox Code Playgroud)
chart.plotContainer.background.stroke = "#ff0000";
Run Code Online (Sandbox Code Playgroud)
var chart = am4core.create("dataChart", am4charts.XYChart);
chart.data = [{
"xValue": "Q1",
"yValue": 3
}, {
"xValue": "Q2",
"yValue": 4
}, {
"xValue": "Q3",
"yValue": 7
}, {
"xValue": "Q4",
"yValue": 2
}, {
"xValue": "Q5",
"yValue": 9
}];
/* Create axes */
var theXAxis = chart.xAxes.push(new am4charts.CategoryAxis());
theXAxis.dataFields.category = "xValue";
theXAxis.renderer.minGridDistance = 30;
theXAxis.renderer.grid.template.stroke = "#ff0000";
theXAxis.renderer.grid.template.strokeWidth = 2;
theXAxis.renderer.grid.template.strokeOpacity = .8; //make the change more visible for demo purposes
// base/zero line
theXAxis.renderer.baseGrid.stroke = "#ff0000";
/* Create value axis */
var theYAxis = chart.yAxes.push(new am4charts.ValueAxis());
theYAxis.renderer.labels.template.disabled = true;
theYAxis.renderer.grid.template.stroke = "#ff0000";
theYAxis.renderer.grid.template.strokeWidth = 2;
theYAxis.renderer.grid.template.strokeOpacity = .8; //make the change more visible for demo purposes
// base/zero line
theYAxis.renderer.baseGrid.stroke = "#ff0000";
//border around chart:
chart.plotContainer.background.stroke = "#ff0000";
/* Create series */
var series1 = chart.series.push(new am4charts.LineSeries());
series1.dataFields.valueY = "yValue";
series1.dataFields.categoryX = "xValue";
series1.bullets.push(new am4charts.CircleBullet());
series1.tooltipText = "{valueY} / 10";
series1.fill = "#2c3e96";
series1.fillOpacity = .3;
series1.stroke = "#4967fa";
/* Create a cursor */
chart.cursor = new am4charts.XYCursor();Run Code Online (Sandbox Code Playgroud)