當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


jQWidgets jqxChart toolTipFormatFunction屬性用法及代碼示例


jQWidgets是一個 JavaScript 框架,用於為 PC 和移動設備製作基於 Web 的應用程序。它是一個非常強大且優化的框架,獨立於平台,並且得到廣泛支持。jqx圖表是一個輕量級且函數強大的圖表小部件,100% 用 JavaScript 編寫。它提供許多高級函數並支持三種不同的渲染技術 - SVG、HTML5 Canvas 和 VML。在本文中,我們將看到 jQWidgets jqxChart 中的 toolTipFormatFunction 屬性。

工具提示格式函數 property 是一個回調函數,用於顯示用戶定義的工具提示文本格式。它是函數類型,其默認值是未定義的。

用法:

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

鏈接文件:下載jQWidgets從給定的鏈接。在 HTML 文件中,找到下載文件夾中的腳本文件。

<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>

示例 1:下麵的示例說明了 jQWidgets jqxChart工具提示格式函數 屬性。

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>

輸出:

示例 2:下麵是jqxChart的另一個例子工具提示格式函數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>

輸出:

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



相關用法


注:本文由純淨天空篩選整理自nidhi1352singh大神的英文原創作品 jQWidgets jqxChart toolTipFormatFunction Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。