amcharts / amcharts5

The newest, fastest, and most advanced amCharts charting library for JavaScript and TypeScript apps.
Other
353 stars 95 forks source link

V5 add legend border & border-radius #1729

Closed flaming-cl closed 1 month ago

flaming-cl commented 2 months ago

Hey, is it possible to add border bottom or border radius for the legend item container?

Legend border radius

image

Legend border bottom

image

Thanks for answering!

martynasma commented 2 months ago

If you need a background with rounded corner, use a RoundedRectangle for itemContainer background:

legend.itemContainers.template.setup = function(target) {
  target.set("background", am5.RoundedRectangle.new(root, {
    fill: am5.color(0x999999)
  }));
};
flaming-cl commented 1 month ago

If you need a background with rounded corner, use a RoundedRectangle for itemContainer background:

legend.itemContainers.template.setup = function(target) {
  target.set("background", am5.RoundedRectangle.new(root, {
    fill: am5.color(0x999999)
  }));
};

Thanks @martynasma! Do you think it's possible to change the border radius of the RoundedRectangle, or it's with some fixed value?

Also for double confirmation, no chance to add any line or border under a legend container, right?

martynasma commented 1 month ago

Do you think it's possible to change the border radius of the RoundedRectangle, or it's with some fixed value?

Yes: https://www.amcharts.com/docs/v5/reference/roundedrectangle/#cornerRadiusBL_setting

Also for double confirmation, no chance to add any line or border under a legend container, right?

Maybe insert a Line into each item container:

legend.itemContainers.template.setup = function(target) {

  target.events.on("boundschanged", function(ev) {
    console.log(ev.target.width(), ev.target.children.getIndex(ev.target.children.length - 1))
    ev.target.children.getIndex(0).setAll({
      points: [
        { x: 0, y: 14 },
        { x: ev.target.width() - ev.target.get("paddingRight", 0), y: 14 }
      ]
    })
  })

  var line = target.children.push(am5.Line.new(root, {
    stroke: am5.color(0x000000),
    strokeOpacity: 0.5,
    isMeasured: false,
    points: []
  }));
};