更改项目符号颜色(amCharts)

问题描述 投票:0回答:1

[尝试更改图表中的项目符号颜色,但不知道如何更改。文档说颜色应该继承,但是不是吗?

Demo

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";

/* Create value axis */
var theYAxis = chart.yAxes.push(new am4charts.ValueAxis());
theYAxis.renderer.labels.template.disabled = true;
theYAxis.renderer.grid.template.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.bullets.push(new am4charts.CircleBullet());
series1.stroke = "#ffbb00";
series1.bullets.stroke = am4core.color("#ffbb00");
series1.bullets.fill = am4core.color("#ffbb00");
body{
  background: grey;
}
<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>

我只希望蓝色子弹像笔画一样变成黄色。

javascript amcharts amcharts4
1个回答
0
投票

series.bullets是一个列表,您不能直接在其上设置视觉属性。您需要从new am4charts.CircleBullet()创建的项目符号对象。 AmCharts网站上的演示使用返回值push并从此处返回:

var bullet = series1.bullets.push(new am4charts.CircleBullet());
series1.stroke = "#ffbb00";
bullet.stroke = am4core.color("#ffbb00");
bullet.fill = am4core.color("#ffbb00");

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";

/* Create value axis */
var theYAxis = chart.yAxes.push(new am4charts.ValueAxis());
theYAxis.renderer.labels.template.disabled = true;
theYAxis.renderer.grid.template.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";

var bullet = series1.bullets.push(new am4charts.CircleBullet());
series1.stroke = "#ffbb00";
bullet.stroke = am4core.color("#ffbb00");
bullet.fill = am4core.color("#ffbb00");
body{
  background: grey;
}
<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>
© www.soinside.com 2019 - 2024. All rights reserved.