question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I change tooltip position to be always on top?

See original GitHub issue

By default Apex Charts tooltip positioning is calculated automatically: https://codepen.io/apexcharts/pen/xYqyYm. According to the docs, you can only change it to fixed and put in one of the corners:

Apex.tooltip = {
    fixed: {
      enabled: true
    }
  };

How do I change it to be always centered on top of the marker?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:6

github_iconTop GitHub Comments

12reactions
simzikovcommented, Jan 4, 2020

In case anyone wants to change the position of tooltips without creating a custom one (cause it poses new difficulties). I am 100% sure there is a better way to do this, but here is my solution:

Apex.chart = {
    events: {
        mouseMove: function(event, chartContext, config) {
            var tooltip = chartContext.el.querySelector('.apexcharts-tooltip');
            var pointsArray = config.globals.pointsArray;
            var seriesIndex = config.seriesIndex;
            var dataPointIndex = config.dataPointIndex === -1 ? 0 : config.dataPointIndex;

            if (seriesIndex !== -1) {
                var position = pointsArray[seriesIndex][dataPointIndex];

                tooltip.style.top = position[1] + 'px';
                tooltip.style.left = position[0] + 'px';
            }
        }
    }
};

Then you can center it with CSS and transform. Thsi works at least for line charts, but I am sure there is a workaround for other types of charts.

3reactions
EeeDotZeecommented, Nov 18, 2020

I wanted to achieve something similiar to what most of the mobile app charts look like (to have a tooltip floating on the top of the chart). I altered the code from @simzikov a little bit, you can check out this codepen. It works fine on a touch device for me. Note: It’s a bit hacky for sure, also tooltips will clip over the menu, but i didn’t need the menu for mobile charts so it works fine if you deactivate it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Apex Charts: how do I change tooltip position to be always on ...
According to their docs, you can only change it to fixed and put in one of the corners:
Read more >
How to: Position a ToolTip - WPF .NET Framework
You can position a tooltip by using a set of five properties that are defined in both the ToolTip and ToolTipService classes.
Read more >
Building a simple tooltip component that never goes off screen
To open the tooltip, we use a class with a modifier (following BEM) tooltip--open . That switches the display property of the dropdown...
Read more >
Tooltip - Chart.js
The xAlign and yAlign options define the position of the tooltip caret. If these parameters are unset, the optimal caret position is determined....
Read more >
Tooltips · Bootstrap v5.0
Hover over the buttons below to see the four tooltips directions: top, right, bottom, and left. Directions are mirrored when using Bootstrap in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found