Open In App

jQWidgets jqxChart toolTipFormatFunction Property

Last Updated : 12 Apr, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

jQWidgets is a JavaScript framework for making web-based applications for PC and mobile devices. It is a very powerful and optimized framework, platform-independent, and widely supported. jqxChart is a lightweight and powerful chart widget written 100% in javascript. It offers many advanced features and supports three different rendering technologies – SVG, HTML5 Canvas & VML. In this article, we will see the toolTipFormatFunction Property in jQWidgets jqxChart.

The toolTipFormatFunction property is a callback function that is used to display the user-defined tooltip text formatting. It is of type function and its default value is undefined.

Syntax:

seriesGroups: [{
   type: 'rangecolumn',
   columnsGapPercent: 30,
   seriesGapPercent: 0,
   toolTipFormatFunction: toolTipCustomFormatFn,
   series: [
           { dataFieldFrom: 'f1', dataFieldTo: 't1'},
            { dataFieldFrom: 'f2', dataFieldTo: 't2'},
     ]
}];

 

Linked Files: Download jQWidgets from the given link. In the HTML file, locate the script files in the downloaded folder.

<link rel=”stylesheet” href=”jqwidgets/styles/jqx.base.css” type=”text/css” />
<script type=”text/javascript” src=”scripts/jquery-1.11.1.min.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqxcore.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqxchart.core.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqxdraw.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqxdata.js”></script>

Example 1: The below example illustrates the jQWidgets jqxChart toolTipFormatFunction property.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <link rel="stylesheet"
        href="jqwidgets/styles/jqx.base.css"
        type="text/css" />
    <script type="text/javascript"
            src="scripts/jquery-1.11.1.min.js">
    </script>
    <script type="text/javascript"
            src="jqwidgets/jqxcore.js">
    </script>
    <script type="text/javascript"
            src="jqwidgets/jqxchart.core.js">
    </script>
    <script type="text/javascript"
            src="jqwidgets/jqxdraw.js">
    </script>
    <script type="text/javascript"
            src="jqwidgets/jqxdata.js">
    </script>
  </head>
  
<body>
    <center>
        <h1 style="color: green">
            GeeksforGeeks
        </h1>
        <h3>
              jQWidgets jqxChart 
            toolTipFormatFunction property
          </h3>
        <div id='gfg1' 
             style="width:400px; 
                    height: 200px" />
    </center>
    <script type="text/javascript">
        $(document).ready(function () {
            var data = [
                { Day: 'Monday', f1: 3, t1: 1, f2: 2, t2: 1 },
                { Day: 'Tuesday', f1: 3, t1: 1, f2: 2, t2: 1 },
                { Day: 'Wednesday', f1: 3, t1: 1, f2: 2, t2: 1 },
                { Day: 'Thursday', f1: 3, t1: 1, f2: 2, t2: 1 },
                { Day: 'Friday', f1: 3, t1: 1, f2: 2, t2: 1 },
                { Day: 'Saturday', f1: 3, t1: 1, f2: 2, t2: 1 },
                { Day: 'Sunday', f1: 3, t1: 1, f2: 2, t2: 1 }
            ];
  
            var toolTipFormatFn = function (val,iIndex,s,grp,cValue) {
                var dItem = data[iIndex];
                return '<DIV style="text-align:left"><b>Day: ' + cValue +
                    '</b><br />Begin: ' + val.from +
                    '<br />End: ' + val.to;
            };
            var obj = {
                title: "Coding Score",
                description: "Coding Questions Solved Daily",
                enableAnimations: true,
                showLegend: true,
                source: data,
                categoryAxis: {
                    dataField: 'Day',
                    showGridLines: true
                },
                seriesGroups: [{
                    type: 'rangecolumn',
                    columnsGapPercent: 30,
                    seriesGapPercent: 0,
                    toolTipFormatFunction: toolTipFormatFn,
                    series: [
                        { dataFieldFrom: 'f1', dataFieldTo: 't1' },
                        { dataFieldFrom: 'f2', dataFieldTo: 't2' },
                    ]
                }]
            };
            $('#gfg1').jqxChart(obj);
        });
    </script>
</body>
  
</html>


Output:

 

Example 2: The following is another example of the jqxChart toolTipFormatFunction property in jQWidgets.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <link rel="stylesheet"
        href="jqwidgets/styles/jqx.base.css"
        type="text/css" />
    <script type="text/javascript"
            src="scripts/jquery-1.11.1.min.js">
    </script>
    <script type="text/javascript"
            src="jqwidgets/jqxcore.js">
    </script>
    <script type="text/javascript"
            src="jqwidgets/jqxchart.core.js">
    </script>
    <script type="text/javascript"
            src="jqwidgets/jqxdraw.js">
    </script>
    <script type="text/javascript"
            src="jqwidgets/jqxdata.js">
    </script>
  </head>
  
<body>
    <center>
        <h1 style="color: green">
            GeeksforGeeks
        </h1>
        <h3>
              jQWidgets jqxChart 
            toolTipFormatFunction property
          </h3>
  
        <div id='gfg1' 
             style="width:400px; 
                    height: 200px" />
    </center>
    <center>
        <input type="button" 
               id="btn" 
               value="Click Here" 
               style="padding: 5px 14px; 
                      margin-top: 15px;">
        <br>
        <div id="log"></div>
    </center>
    <script type="text/javascript">
        $(document).ready(function () {
            var data = [
                { Day: 'Monday', f1: 3, t1: 1, f2: 2, t2: 1 },
                { Day: 'Tuesday', f1: 3, t1: 1, f2: 2, t2: 1 },
                { Day: 'Wednesday', f1: 3, t1: 1, f2: 2, t2: 1 },
                { Day: 'Thursday', f1: 3, t1: 1, f2: 2, t2: 1 },
                { Day: 'Friday', f1: 3, t1: 1, f2: 2, t2: 1 },
                { Day: 'Saturday', f1: 3, t1: 1, f2: 2, t2: 1 },
                { Day: 'Sunday', f1: 3, t1: 1, f2: 2, t2: 1 }
            ];
  
            var toolTipFormatFn = function (val, iIndex, s, grp, cValue) {
                var dItem = data[iIndex];
                return '<DIV style="text-align:left"><b>Day: ' + cValue +
                    '</b><br />Begin: ' + val.from +
                    '<br />End: ' + val.to;
            };
            var obj = {
                title: "Coding Score",
                description: "Coding Questions Solved Daily",
                enableAnimations: true,
                showLegend: true,
                source: data,
                categoryAxis: {
                    dataField: 'Day',
                    showGridLines: true
                },
                seriesGroups: [{
                    type: 'rangecolumn',
                    columnsGapPercent: 30,
                    seriesGapPercent: 0,
                    toolTipFormatFunction: toolTipFormatFn,
                    series: [
                        { dataFieldFrom: 'f1', dataFieldTo: 't1' },
                        { dataFieldFrom: 'f2', dataFieldTo: 't2' },
  
  
                    ]
                }]
            };
            $('#gfg1').jqxChart(obj);
            $('#btn').click(function () {
                var ttff = $('#gfg1').jqxChart('toolTipFormatFunction');
                if (ttff === null) {
                    $('#log').text("Null!");
                }
                else {
                    $('#log').text("Not null!");
                }
            });
        });    
    </script>
</body>
  
</html>


Output:

 

Reference: https://www.jqwidgets.com/jquery-widgets-documentation/documentation/jqxchart/jquery-chart-api.htm?search=



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads