1

As part of my Highchart POC I am trying to achive change a

  1. labelcolor of x-axis on click of particular lable on x-axis
  2. want to read the current x-axis lable and y-axis data

but click event only not firing,, on load I achievd the lable color, but I am tring to do it on same thing on click event

https://stackblitz.com/edit/highcharts-angular-demo-t8pmf4?embed=1&file=src/app/app.component.ts

Can any one can help me or suggest me

As per solution provided below I acheived 50% https://stackblitz.com/edit/highcharts-angular-demo-z84bav?embed=1&file=src/app/app.component.ts

but how to change label color ??

Thanks in advance

Soumya Gangamwar
  • 954
  • 4
  • 16
  • 44

3 Answers3

1

events should be inside the labels object, now your click handler will trigger.

xAxis: {
        categories: ["4-10/10", "11-17/10", "18-24/10", "25-31/10"],
        labels: {
          formatter: function() {
            if ("18-24/10" === this.value) {
              return '<span style="fill: red;">' + this.value + "</span>";
            } else {
              return this.value;
            }
          },
          events: {
             click: function() {
            console.log("click");
           }
          }
        },
Sarun UK
  • 6,210
  • 7
  • 23
  • 48
1

To add the click event and change the color in the event use the below code:

    xAxis: {
        ...,
        labels: {
            ...,
            events: {
                click: function() {
                    this.axis.ticks[this.pos].label.css({
                        color: 'red'
                    });
                }
            }
        }
    }

Live example: http://jsfiddle.net/BlackLabel/1nyk6c5b/

Docs: https://www.highcharts.com/plugin-registry/single/15/Custom-Events

ppotaczek
  • 36,341
  • 2
  • 14
  • 24
0

Use this logic to do that,

chart.xAxis[0].labelGroup.element.childNodes.forEach(function(label)
{
    label.style.cursor = "pointer";
    label.onclick = function(){
      alert('You clicked on '+this.textContent);
    }
});

This example contains Label as well as Bar click: http://jsfiddle.net/m4b0eozd/

Malik Zahid
  • 593
  • 5
  • 13