最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Add styles to AmCharts 4 labels - Stack Overflow

programmeradmin2浏览0评论

I have a cylinder bar chart in AmCharts 4 that uses a darker color scheme. The text color for the labels on the bars is black and is not really showing on darker colors.

- I am using the javascript code illustrated in AmChart's Demos for the Cylinder 3D Chart.

Is there a way to add css to the label/label text?

I would like to add a white text-shadow to the label to make it readable. Also, this way, it won't affect the text when it is over the white chart background.

Edit: 12/18/2018 - I am looking for the text to be closer to something like this:

These will be able to be seen, even if the bar is short and the text lays against the white background.

I have a cylinder bar chart in AmCharts 4 that uses a darker color scheme. The text color for the labels on the bars is black and is not really showing on darker colors.

- I am using the javascript code illustrated in AmChart's Demos for the Cylinder 3D Chart.

Is there a way to add css to the label/label text?

I would like to add a white text-shadow to the label to make it readable. Also, this way, it won't affect the text when it is over the white chart background.

Edit: 12/18/2018 - I am looking for the text to be closer to something like this:

These will be able to be seen, even if the bar is short and the text lays against the white background.

Share Improve this question edited Dec 18, 2018 at 19:49 Eric asked Dec 7, 2018 at 15:23 EricEric 5613 gold badges7 silver badges14 bronze badges 1
  • I assume it's using svg and plopping it in a transformed svg text element. So could do css like svg text { color: red; background-color: white } – Chris W. Commented Dec 7, 2018 at 19:45
Add a ment  | 

2 Answers 2

Reset to default 10

You could set fill to the labels template:

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

Please check the example here: https://codepen.io/team/amcharts/pen/3446cd09288ee4e5901c73b3970adbfe?editors=0010

You can use CSS to add a white stroke to SVG text. First enable CSS classes for amCharts 4:

am4core.options.autoSetClassName = true;

And then add this to your CSS:

@supports (paint-order: stroke) {
  .amcharts-LabelBullet text {
    paint-order: stroke;
    stroke: #fff;
    stroke-width: 4px;
    stroke-linecap: butt;
    stroke-linejoin: miter;
    stroke-opacity: 1;
  }
}

This will add a 4px white outline to all LabelBullet text.

发布评论

评论列表(0)

  1. 暂无评论