apexcharts / react-apexcharts

📊 React Component for ApexCharts
https://apexcharts.com
MIT License
1.31k stars 158 forks source link

Adding y-axis label as link #70

Closed Mala001 closed 1 month ago

Mala001 commented 5 years ago

Hi,

Im trying to make the y-axis label as link(anchor tag) by using the below code and called it in beforemount but the label is changing as link for a time being and loads as normal text after that. Please guide me how to achieve the link.I'm using the below code.

$('.apexcharts-yaxis-texts-g').find('text').each(function(i, elm) {
p = elm.parentNode; if ('g' === p.tagName.toLowerCase()) { if (-1 !== i) { / wrap text tag with anchor tag / n = document.createElementNS('http://www.w3.org/2000/svg', 'a'); n.setAttributeNS(ns, 'xlink:href', '#');
n.appendChild(p.removeChild(elm)); p.appendChild(n); } } });

HiLuLiT commented 4 years ago

This worked for me (using React component life cycles, seems like you're using jquery): I gave each div the name of the label, so when clicking on a label it will scroll to that div. Also I checked the dev tools to get the labels classNames, so they may vary from this example:

componentDidMount () {
    const labels = document.querySelectorAll('.apexcharts-text.apexcharts-yaxis-label')
    labels.forEach(item => {
      item.addEventListener('click', event => {
        const hash = event.target.innerHTML.toLowerCase()
        const elm = document.getElementById(hash)
        elm.scrollIntoView()
      })
    })
  }
github-actions[bot] commented 1 month ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.