Tooltip for flot bar chart

社会主义新天地 提交于 2019-12-03 10:01:15

Not sure what you were trying to achieve with

$.fn.UseTooltip = function () {
            $(this).bind("plothover", function (event, pos, item) {

But try replacing with this:

$("#placeholder2").on("plothover", function (event, pos, item) {
    if (item) {
// and removing trailling } in the end

Demo

Your code is almost ok, there is just single peace is missing.

To understand what peace and why it is missing you should first understand what 'prototype' is and how jQuery use it. In short words - prototype is and object which defines default property values/method implementations for some other object. '$.fn' in jQuery is short reference to prototype. So calling

$.fn.UseTooltip = function () { ... }

will create default implementation for function UseTooltip for all object created by jQuery - e.g. now you can call $(someSelector).UseTooltip(some-parameters).

The important thing in your code is in the fact, that although you defined this function, you never invoked it. This means that you didn't attach tooltip to your bar chart. Simply add:

$("#placeholder2").UseTooltip()

This should solve you problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!