如何改变amcharts4中values/categories的文字颜色?
how to change the text s color of values/categories in amcharts4?
我想更改类别的颜色和文本的值(参见嵌入的图片),我不确定它是否与我的 css 样式或 amcharts 有关api。但是我确实设法用 label.fill = am4core.color("white");
更改了标签
.chartdiv {
padding: 10px 10px;
background: #1a2035;
font-size: 12px;
line-height: 11px;
width: 610px;
border-radius: 15px;
border-style: solid;
border-color: #1a2035;
border-width: 1px;
opacity: 0.75;
}
.chartdiv .ImpactHeader {
line-height: 14px;
text-align: center;
font-weight: 600;
margin-bottom: 5px;
}
.chartdiv .ImpactLead {
font-weight: 500;
}
.chartdiv .ImpactCount {
text-align: right;
font-weight: 600;
}
.chartdiv .ImpactEnd {
font-weight: 500;
}
.chartdiv:empty {
display: none;
}
和代码:
am4core.ready(function() {
const units = 'km';
// Themes begin
am4core.useTheme(am4themes_animated);
// Themes end
// Create chart instance
chart = am4core.create("chartdiv", am4charts.XYChart);
// Add data
chart['data'] = [{"country":"","volume":'','Name':''}];
// Create axes
var categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "country";
categoryAxis.renderer.grid.template.location = 10;
categoryAxis.renderer.minGridDistance = 20;
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
// Create series
var series = chart.series.push(new am4charts.ColumnSeries());
series.dataFields.valueY = "volume";
series.dataFields.categoryX = "country";
series.dataFields.countryNameX = "c_name";
series.name = "volume";
series.columns.template.tooltipText = "{countryNameX}: [bold]{valueY}[/] "+units;
series.columns.template.fillOpacity = .8;
//label units on left side
var label = chart.createChild(am4core.Label);
label.text = units;
label.fontSize = 16;
label.align = "left";
label.rotation=270;
label.isMeasured = false;
label.x = -10;
label.y = 50;
label.fill = am4core.color("white");
var columnTemplate = series.columns.template;
columnTemplate.strokeWidth = 1;
columnTemplate.strokeOpacity = 1;
});
您需要按照记录直接在轴对象的标签模板上设置颜色 here:
categoryAxis.renderer.labels.template.fill = am4core.color("#ffffff");
valueAxis.renderer.labels.template.fill = am4core.color("#ffffff");
我想更改类别的颜色和文本的值(参见嵌入的图片),我不确定它是否与我的 css 样式或 amcharts 有关api。但是我确实设法用 label.fill = am4core.color("white");
.chartdiv {
padding: 10px 10px;
background: #1a2035;
font-size: 12px;
line-height: 11px;
width: 610px;
border-radius: 15px;
border-style: solid;
border-color: #1a2035;
border-width: 1px;
opacity: 0.75;
}
.chartdiv .ImpactHeader {
line-height: 14px;
text-align: center;
font-weight: 600;
margin-bottom: 5px;
}
.chartdiv .ImpactLead {
font-weight: 500;
}
.chartdiv .ImpactCount {
text-align: right;
font-weight: 600;
}
.chartdiv .ImpactEnd {
font-weight: 500;
}
.chartdiv:empty {
display: none;
}
和代码:
am4core.ready(function() {
const units = 'km';
// Themes begin
am4core.useTheme(am4themes_animated);
// Themes end
// Create chart instance
chart = am4core.create("chartdiv", am4charts.XYChart);
// Add data
chart['data'] = [{"country":"","volume":'','Name':''}];
// Create axes
var categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "country";
categoryAxis.renderer.grid.template.location = 10;
categoryAxis.renderer.minGridDistance = 20;
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
// Create series
var series = chart.series.push(new am4charts.ColumnSeries());
series.dataFields.valueY = "volume";
series.dataFields.categoryX = "country";
series.dataFields.countryNameX = "c_name";
series.name = "volume";
series.columns.template.tooltipText = "{countryNameX}: [bold]{valueY}[/] "+units;
series.columns.template.fillOpacity = .8;
//label units on left side
var label = chart.createChild(am4core.Label);
label.text = units;
label.fontSize = 16;
label.align = "left";
label.rotation=270;
label.isMeasured = false;
label.x = -10;
label.y = 50;
label.fill = am4core.color("white");
var columnTemplate = series.columns.template;
columnTemplate.strokeWidth = 1;
columnTemplate.strokeOpacity = 1;
});
您需要按照记录直接在轴对象的标签模板上设置颜色 here:
categoryAxis.renderer.labels.template.fill = am4core.color("#ffffff");
valueAxis.renderer.labels.template.fill = am4core.color("#ffffff");