Изменить цвет пули (amCharts) - PullRequest
       13

Изменить цвет пули (amCharts)

0 голосов
/ 16 февраля 2020

Пытаюсь изменить цвет маркера на моем графике, но не могу понять как. Документы говорят, что цвет должен наследовать, но это не так?

Демо :

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>

Я просто хочу, чтобы синие пули стали желтыми, как удар.

1 Ответ

0 голосов
/ 19 февраля 2020

series.bullets - список, вы не можете установить визуальные свойства непосредственно для него. Вам нужен объект маркера, который вы создаете из new am4charts.CircleBullet(); демонстрации на веб-сайте AmCharts используют возвращаемое значение push и go оттуда:

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>
...