我正在使用amchart4开发分析仪表板以呈现图形。 但是我不知道如何根据条件更改子弹的颜色
var series2 = chart.series.push(new am4charts.LineSeries());
series2.dataFields.valueX = "PROJ_LF";
series2.dataFields.categoryY = "Roundtrip_Market";
series2.strokeWidth = 0;
var bullet1 = series2.bullets.push(new am4charts.Bullet());
bullet1.tooltipText = "Value: [bold]{valueX} %[/]";
var image = bullet1.createChild(am4core.Image);
image.href = "assets/images/proj_lf_red.png";
image.width = 7;
image.height = 41;
image.horizontalCenter = "middle";
image.verticalCenter = "middle";
var series3 = chart.series.push(new am4charts.LineSeries());
series3.dataFields.valueX = "LY_FLOWN";
series3.dataFields.categoryY = "Roundtrip_Market";
series3.strokeWidth = 0;
var bullet2 = series3.bullets.push(new am4charts.Bullet());
bullet2 .tooltipText = "Value: [bold]{valueX} %[/]";
var image1 = bullet2.createChild(am4core.Image);
image1.href = "assets/images/ly_flow.png";
image1.width = 7;
image1.height = 41;
image1.horizontalCenter = "middle";
image1.verticalCenter = "middle";
问题是关于bullet1,bullet2 现在,bullet1颜色为红色,bullet2为黑色 但是,我需要动态地改变颜色 如果bullet1> bullet2 bullet1颜色为红色
如果bullet2> bullet1 bullet1颜色将为绿色
答案 0 :(得分:0)
我知道这个问题已有7个月大了,但是我遇到了类似的问题并找到了解决方案。
您可以先遍历数据数组,然后再将其分配给图表并添加基于条件的属性,如下所示:
config = {
fill: am4core.color('#ff0000'),
};
现在,您可以将dataField
属性添加到图表的那部分,在我的情况下,该部分将获得另一种颜色:
series.columns.template.configField = 'config';
现在,图表将考虑您的数据项是否具有config属性,并更改此特定条目的配置中列出的任何设置。