Interactive tooltip feature in Apexchart

I need to include % in my Apexcharts tooltip after the Y value. Working with vue.js and without official documentation from apexchart, I managed to make it function correctly. This is what I have accomplished so far:

data: function () {
    return {
      apex: null
    }
  },

  // Code handling the chart without official vue.js documentation for apexcharts, but there's javascript documentation available
  //https://apexcharts.com/docs/installation/
  methods: {
      init: function() {
            this.apex = new ApexCharts(this.$refs.barchart, {
            chart: {
                type: 'line',
                height:400,
                animations: {
                    enabled: true,
                    easing: 'easeinout',
                    speed: 800,
                    animateGradually: {
                        enabled: true,
                        delay: 50
                    },
                    dynamicAnimation: {
                        enabled: true,
                        speed: 800
                    }
                },
                toolbar: {
                    show: true,
                    tools: {
                        download: true,
                        selection: false,
                        zoom: false,
                        zoomin: true,
                        zoomout: true,
                        pan: true,
                        reset: true
                    },
                    autoSelected: 'zoom' 
                },
            },
            stroke: {
                width: 3,
                curve: 'smooth'
            },
            series: [{
                name: this.bar1name,
                data: [28 , 29, 33, 30, 26, this.bar1number2, this.bar1number1]
                },
                {
                name: this.bar2name,
                data: [12, 11, 14, 26, 28, this.bar2number2, this.bar2number1]
                },
                {
                name: this.bar3name,
                data: [32, 41, 40, 44, 47, this.bar3number2, this.bar3number1]
                },
                {
                name: this.bar4name,
                data: [48, 41, 33, 37, 35, this.bar4number2, this.bar4number1]
                },
                {
                name: this.bar5name,
                data: [52, 56, 60, 54, 52, this.bar5number2, this.bar5number1]
                },
                {
                name: this.bar6name,
                data: [32, 27, 38, 48, 30, this.bar6number2, this.bar6number1]
            }],
            colors:[this.chart1color, this.chart2color, this.chart3color,this.chart4color,this.chart5color,this.chart6color],    
            markers: {
                colors: [this.chart1color, this.chart2color, this.chart3color,this.chart4color,this.chart5color,this.chart6color],
                hover:{size:6}
            },
            xaxis: {
                type:'datetime',
                categories: ['Jan 2018', 'Feb 2018', 'Mar 2018', 'Apr 2018', 'May 2018', 'Jun 2018', 'Jul 2018'],
                axisTicks: {
                    show: true,
                    borderType: 'solid',
                    color: '#78909C',
                    height: 6,
                },
            }, 
            yaxis: {
                tickAmount: 5,
                min: 0,
                max: 100,
            },
            grid: {
                show: true,
                borderColor: '#e8e8e8',
                strokeDashArray: 0,
                position: 'back',
                xaxis: {
                    lines: {
                        show: true,
                        offsetX: 10,
                        offsetY: 10,
                    }
                },   
                yaxis: {
                    lines: {
                        show: true,
                        offsetX: 10,
                        offsetY: 10
                    },
                    tickAmount: 6,
                    min: 0,
                    max: 100,
                },  
                padding: {
                    top: 0,
                    right: 0,
                    bottom: 0,
                    left: 0
                },  

            },
            tooltip: {
                enabled: true,
                followCursor: true,
                x: {
                    format: 'dd MMM',
                    formatter: undefined,
                },

                yaxis: {
                    labels: {
                        formatter: (value) => { return val + "%" },
                    },
                },

            },  

            }).render()
      }
  },
mounted() {
      this.init();
  },
  updated() {
      this.init();
  }
}

I attempted using the formatter to modify the outcome as follows, but it wasn't successful.

tooltip: {
      enabled: true,
      followCursor: true,
      x: {
          format: 'dd MMM',
          formatter: undefined,
      },

      yaxis: {
          labels: {
              formatter: (value) => { return val + "%" },
          },
      },              
  },

Any assistance or references would be greatly appreciated. Thank you.

Since Stack won't allow me to add a new tag for apex charts, here's the official documentation link: Apexcharts

Answer №1

Looks like the yaxis options got mixed up with the tooltip label formatter.

Give this code a try:

tooltip: {
  x: {
    format: 'dd MMM',
    formatter: undefined,
  },
  y: {
    formatter: (value) => { return value + "%" },
  },              
}

Furthermore, there's a vue.js wrapper specifically designed for ApexCharts that you might find useful.

https://github.com/apexcharts/vue-apexcharts

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble using the `.not` function in jQuery

I'm working on implementing a collapsible menu using jQuery. When any header is clicked, the next sibling (the box) should expand while all other boxes collapse. HTML <div class="finbox" id="finbox1"> <div class="finheader" id="finheade ...

Sending parameter and ng-click to the angular directive

I am looking for a way to transfer data from HTML to the directive, allowing the directive to be clickable using ng-click. How can I pass the parameter of the link function to the template? app.directive("hello", function(){ return { restrict: "E" ...

Running npm commands from the root directory while the package.json file is located elsewhere

Although I understand that it's not ideal, I am faced with a specific directory structure that cannot be changed: [projectRootDir] [src] [tests] [otherDirs] [configuration] package.json mocha.opts other files.. ...

Performing a sequence of actions using Jquery Queue() function and iterating through each

I am facing an interesting challenge with an array called result[i]. My goal is to iterate through each field in the array and add it to a specific element on my webpage. $("tr:first").after(result[i]); However, I would like this process to happen with a ...

Incorporating a JSON file through a script element

A customized I18n plugin has been developed to accept various languages through json files. The goal is to simplify usage for users by allowing them to easily insert their json package directly into a page along with the script: <script id="pop-languag ...

Instructions for including a script and stylesheet exclusively on a single page of a website

I need to incorporate these two lines onto a single page of my website: <script src="//cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.js"></script> As well as <link href="//cdnjs.cloudflare.com/ajax/libs/OwlCa ...

The Vue transition classes fail to properly function when entering and exiting

I have created a codepen featuring a simple flip card. The code works perfectly in Codepen, but when I integrate it into my Vue project generated with vue cli, there seems to be an issue. While clicking on a card displays its back, the transition effect th ...

Creating an if statement that validates whether all variables have non-null values

I am still getting the hang of javascript and working on some coding projects from my textbooks. The current task involves creating an if statement to check if the values of the elements referenced by the names fname, lname, and zip are all not null. Here ...

Guidance on utilizing jQuery to display values depending on a dropdown selection

This code snippet displays movie data from a JSON variable in a dropdown list based on the selected city. It also needs to show the movie name and theaters list when a user selects a movie, along with the theater dropdown remaining unchanged. Here is my H ...

JSON object containing elements with dash (-) character in their names

While I am in the process of parsing a `json` object, I encountered an element labeled as `data-config`. Here's an example: var video = data.element.data-config; Every time I attempt to parse this specific element, an error pops up: ReferenceError ...

Executing a Drupal rule using JavaScript: A step-by-step guide

I'm facing a challenge when trying to activate a Drupal rule using JavaScript code. lowerLayer[image.feature_nid].on("dragend", function() { var position = kineticImage.getPosition(); var layerPosition = this.getPo ...

Learn the step-by-step process of clicking on a button to modify its properties and deactivate it

I could really use some assistance. I'm trying to make a button: <v-btn dark color="primary" class="square">Tile 1</v-btn> Is there a way I can modify it so that when clicked, it changes to flat, becomes disabled, and switches its color ...

Looking for a simple method to link JSON data to an svg element through Javascript?

Looking to harness the power of SVG for a basic graph creation, but uncertain about the process of assigning JSON data dynamically using a 'for loop' to draw rectangles within SVG. Seeking guidance on setting up 1 loop to assign each value for dr ...

Adding a JavaScript script tag within a React app's ComponentDidMount - a guide

I am currently in the process of implementing Google Optimize on my website. I need to include the following script tag within my page: <script>(function(a,s,y,n,c,h,i,d,e){s.className+=' '+y;h.start=1*new Date; h.end=i=function(){s.classN ...

What is a way to retain the value of a variable after a request, while starting off with a different value on the initial load?

In my Flask application, users have the option to choose a specific time period with a start date and an end date. When the page initially loads, I want the start date to default to the first day of the current month and the end date to be the current day. ...

Retrieve data from the table and dropdown menu by clicking a button

A script is in place that retrieves data from two columns (Members, Description) dynamically from the table upon button click. Table html Here is the JQuery code responsible for extracting values from the table: $(function() { $('#myButton') ...

The error occurs when Facebook and Twitter iframes are attempting to access and set 'document.domain'

When attempting to add Tweet and Facebook Like buttons to the project I'm working on, everything appears to be functioning properly. However, upon clicking the buttons, a JavaScript error occurs: Unsafe JavaScript attempt to access frame with URL htt ...

The icon displays correctly in Firefox but is not visible in IE

link REL="SHORTCUT ICON" HREF="/images/greenTheme/favicon.ico" type="image/x-icon" While this code functions properly in Firefox, it appears to be causing issues in Internet Explorer. Can anyone provide guidance on how to resolve the compatibility issue w ...

Aligning a div vertically in the center of its parent container

I am trying to vertically align a child element within its parent element <!DOCTYPE html> <html> <head> <title>Test</title> <style type="text/css"> #body { font-family: sans-serif, arial, 'Roboto'; } #outer ...

Unit tests manipulating JavaScript functions to return undefined values

Currently, I am in the process of testing some JavaScript functions within a larger React application. These functions heavily utilize the module pattern, which leads me to believe that my misunderstanding lies within this pattern. The script I am testing ...