Search code examples
hyperlinkseriesapexcharts

Apexchart Timeline: How can i set a custom link to each bars of a series


I'm using a Apexchart Timeline and I need to pass a custom url from each bar on click.

Here is an example of the series:

series: [{
  name: "series"
  data: [{
    x: "element 1"
    y: 10
    z: "https://google.com"
  }, {
    x: "element 2"
    y: 20
    z: "https://yahoo.com"
  }]
}, {
  name: "series2"
  data: [{
    x: "element 3"
    y: 10
    z: "https://stackoverflow.com"
  }]
}], 

I'm trying to buil the onclick event

chart: {                          
    type: 'rangeBar',
    events: {
            dataPointSelection: function(event, chartContext, config) {

                window.location = obj.w.config.series[obj.seriesIndex].data[obj.dataPointIndex].z;
                    
        }
    }
}

But it doesn't works..

Any idea how to fix it?

I tried also with this:

events: {
    dataPointSelection: function(event, chartContext, config) {

        return document.location.href = obj.w.config.series[obj.seriesIndex].data[obj.dataPointIndex].z;
    }
}

No way


Solution

  • You should rename config into obj:

    events: {
        dataPointSelection: function(event, chartContext, obj) {
            return document.location.href = obj.w.config.series[obj.seriesIndex].data[obj.dataPointIndex].z;
        }
    }