如何在 amCharts 4 中绘制堆积条形图的轮廓?

How to outline a stacked bar chart in amCharts 4?

我目前在 amCharts 4 中使用 Stacked XYChart,并且我只显示一个柱:

我正在尝试弄清楚如何在 整个 栏周围绘制轮廓 - 如下所示:

我已经尝试将 stroke(以及 strokeWidthstrokeOpacity)属性 添加到几乎所有内容 - 系列、yAxes、xAxes 等,但其中 none 产生了我希望的结果。我觉得我缺少了一些明显的东西,所以非常感谢任何帮助。

我认为这是我们可以实现的。它不会根据您的要求提供连续行程。 你可能试过这个。

function createSeries(field, name) {
  var series = chart.series.push(new am4charts.ColumnSeries());
  series.dataFields.valueX = field;
  series.dataFields.categoryY = "year";
  series.stacked = true;
  series.name = name;
  series.stroke = am4core.color("#000");
  
  var labelBullet = series.bullets.push(new am4charts.LabelBullet());
  labelBullet.locationX = 0.5;
  labelBullet.label.text = "{valueX}";
  labelBullet.label.fill = am4core.color("#fff");
}

代码库 - https://jsfiddle.net/sarunuk/dyohfr68/1/

既然你提到你只显示一列并假设这是一个 100% 堆叠图表,你能做的最好的就是在图表的 plotContainer:

上设置一个笔划
chart.plotContainer.stroke = "#000000"

请注意,您的系列列需要将高度设置为 100%,这样它才能在容器内完全展开 (series.columns.template.height = am4core.percent(100))。

下面的演示:

var chart = am4core.create("chartdiv", am4charts.XYChart);

chart.data = [{
  "year": "2016",
  "europe": 2.5,
  "namerica": 2.5,
  "asia": 2.1,
  "lamerica": 0.3,
  "meast": 0.2,
  "africa": 0.1
}];

chart.legend = new am4charts.Legend();
chart.legend.position = "top";

chart.plotContainer.stroke = "#000000";
chart.plotContainer.strokeWidth = 5;

var categoryAxis = chart.yAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "year";
categoryAxis.renderer.grid.template.opacity = 0;
categoryAxis.renderer.labels.template.disabled = true;

var valueAxis = chart.xAxes.push(new am4charts.ValueAxis());
valueAxis.min = 0;
valueAxis.max = 100;
valueAxis.strictMinMax = true; 
valueAxis.renderer.grid.template.opacity = 0;
valueAxis.renderer.labels.template.disabled = true;
valueAxis.renderer.baseGrid.disabled = true;
valueAxis.calculateTotals = true;


function createSeries(field, name) {
  var series = chart.series.push(new am4charts.ColumnSeries());
  series.dataFields.valueX = field;
  series.dataFields.categoryY = "year";
  series.dataFields.valueXShow = "totalPercent";
  series.stacked = true;
  series.name = name;
  series.columns.template.height = am4core.percent(100);
}

createSeries("europe", "Europe");
createSeries("namerica", "North America");
createSeries("asia", "Asia");
createSeries("lamerica", "Latin America");
createSeries("meast", "Middle East");
createSeries("africa", "Africa");
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}

#chartdiv {
  width: 100%;
  height: 200px;
}
<script src="https://cdn.amcharts.com/lib/4/core.js"></script>
<script src="https://cdn.amcharts.com/lib/4/charts.js"></script>
<div id="chartdiv"></div>