【问题标题】:how to change the text s color of values/categories in amcharts4?如何更改文本是 amcharts 4 中值/类别的颜色?
【发布时间】:2020-09-17 18:57:21
【问题描述】:

我想更改类别的颜色和文本的值(参见嵌入图片),我不确定它是否与我的 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;       
    }); 

【问题讨论】:

    标签: graph colors amcharts


    【解决方案1】:

    您需要直接在轴对象的标签模板上设置颜色,如文档here

    categoryAxis.renderer.labels.template.fill = am4core.color("#ffffff");
    valueAxis.renderer.labels.template.fill = am4core.color("#ffffff");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-09
      • 2019-05-27
      • 2019-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多