Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Amcharts 4 scrollbar color?

I am trying to set scrollbar color in Amcharts, but none of the options specified on Amcharts site has worked.

I am using "@amcharts/amcharts4": "^4.2.2" in react app.

I have tried many options which are mentioned below. None of them are working.

chart.scrollbarX = new am4core.Scrollbar();
chart.scrollbarX.fill = "#017acd";
chart.scrollbarX.setFill(new am4core.color("#017acd"));
chart.scrollbarX.setStroke(new am4core.color("#017acd"));
chart.scrollbarX.stroke = "#017acd"; //this sets the border line color of 
scrollbar.

Thanks for the help.

like image 465
vinod Avatar asked Feb 03 '23 19:02

vinod


1 Answers

A scrollbar has a background, a thumb, a startGrip and an endGrip. Each of them can be styled individually by :

chart.scrollbarX.background.fill = am4core.color("#017acd");
chart.scrollbarX.thumb.background.fill = am4core.color("#017acd");
chart.scrollbarX.startGrip.background.fill = am4core.color("#017acd");
chart.scrollbarX.endGrip.background.fill = am4core.color("#017acd");
chart.scrollbarX.stroke = am4core.color("#017acd");

You can create different states for all the components to set different colors for hover or press (down).

chart.scrollbarX.thumb.background.states.getKey('hover').properties.fill = am4core.color("#017acd");
chart.scrollbarX.thumb.background.states.getKey('down').properties.fill = am4core.color("#017acd");

I created this code pen to show you a complete example.

If you want to style not a single scrollbar, but all the scrollbars in your app I would suggest creating a custom theme for that.

function am4themes_myTheme(target) {
  if (target instanceof am4core.InterfaceColorSet) {
    target.setFor("secondaryButton", am4core.color("#6DC0D5"));
    target.setFor("secondaryButtonHover", am4core.color("#6DC0D5").lighten(-0.2));
    target.setFor("secondaryButtonDown", am4core.color("#6DC0D5").lighten(-0.2));
    target.setFor("secondaryButtonActive", am4core.color("#6DC0D5").lighten(-0.2));
    target.setFor("secondaryButtonText", am4core.color("#FFFFFF"));
    target.setFor("secondaryButtonStroke", am4core.color("#467B88"));
  }
  if (target instanceof am4core.Scrollbar) {
    target.stroke = am4core.color("#017acd");
  }
}

am4core.useTheme(am4themes_myTheme);

Here is a code pen showing a theme example.

like image 172
Samuel Philipp Avatar answered Apr 27 '23 17:04

Samuel Philipp