Chart JS custom tooltip option?

后端 未结 7 762
野趣味
野趣味 2020-12-03 03:44

I am trying to build chart using Chart.Js. This chart.js has default option for tooltip, I want to make customized tooltip option. Is there a way to make it possible?

<
7条回答
  •  情深已故
    2020-12-03 04:12

    Try this:

    You can make changes globally using this code:

    Chart.defaults.global = {
    
        // Boolean - Determines whether to draw tooltips on the canvas or not
        showTooltips: true,
    
        // Array - Array of string names to attach tooltip events
        tooltipEvents: ["mousemove", "touchstart", "touchmove"],
    
        // String - Tooltip background colour
        tooltipFillColor: "rgba(0,0,0,0.8)",
    
        // String - Tooltip label font declaration for the scale label
        tooltipFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
    
        // Number - Tooltip label font size in pixels
        tooltipFontSize: 14,
    
        // String - Tooltip font weight style
        tooltipFontStyle: "normal",
    
        // String - Tooltip label font colour
        tooltipFontColor: "#fff",
    
        // String - Tooltip title font declaration for the scale label
        tooltipTitleFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
    
        // Number - Tooltip title font size in pixels
        tooltipTitleFontSize: 14,
    
        // String - Tooltip title font weight style
        tooltipTitleFontStyle: "bold",
    
        // String - Tooltip title font colour
        tooltipTitleFontColor: "#fff",
    
        // Number - pixel width of padding around tooltip text
        tooltipYPadding: 6,
    
        // Number - pixel width of padding around tooltip text
        tooltipXPadding: 6,
    
        // Number - Size of the caret on the tooltip
        tooltipCaretSize: 8,
    
        // Number - Pixel radius of the tooltip border
        tooltipCornerRadius: 6,
    
        // Number - Pixel offset from point x to tooltip edge
        tooltipXOffset: 10,
    
        // String - Template string for single tooltips
        tooltipTemplate: "<%if (label){%><%=label%>: <%}%><%= value %>",
    
        // String - Template string for single tooltips
        multiTooltipTemplate: "<%= value %>",
    
        // Function - Will fire on animation progression.
        onAnimationProgress: function(){},
    
        // Function - Will fire on animation completion.
        onAnimationComplete: function(){}
    }
    

    Use this Link for reference

提交回复
热议问题