ABPCMS.Web/lib/Flot/PLUGINS.md

(开头部分) 4KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

## Writing plugins ##

All you need to do to make a new plugin is creating an init function
and a set of options (if needed), stuffing it into an object and
putting it in the $.plot.plugins array. For example:

```js
function myCoolPluginInit(plot) {
    plot.coolstring = "Hello!";
};

$.plot.plugins.push({ init: myCoolPluginInit, options: { ... } });

// if $.plot is called, it will return a plot object with the
// attribute "coolstring"
```

Now, given that the plugin might run in many different places, it's
a good idea to avoid leaking names. The usual trick here is wrap the
above lines in an anonymous function which is called immediately, like
this: (function () { inner code ... })(). To make it even more robust
in case $ is not bound to jQuery but some other Javascript library, we
can write it as

```js
(function ($) {
    // plugin definition
    // ...
})(jQuery);
```

There's a complete example below, but you should also check out the
plugins bundled with Flot.


## Complete example ##
  
Here is a simple debug plugin which alerts each of the series in the
plot. It has a single option that control whether it is enabled and
how much info to output:

```js
(function ($) {
    function init(plot) {
        var debugLevel = 1;

        function checkDebugEnabled(plot, options) {
            if (options.debug) {
                debugLevel = options.debug;
                plot.hooks.processDatapoints.push(alertSeries);
            }
        }

        function alertSeries(plot, series, datapoints) {
            var msg = "series " + series.label;
            if (debugLevel > 1) {
                msg += " with " + series.data.length + " points";
                alert(msg);
            }
        }
后面还有 83 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。