0

我只在 jqplot.pointlabels.js 文件中添加了几行,所以我在 jqplot pointlabels 选项中获得了一个额外的选项。我该如何为此制作一个新插件?

当然,如果我需要更新,我喜欢保留这些更改。我不知道该怎么做。我正在尝试制作时间线/甘特图。每个项目或线段是一个只有两个点的系列。因此,我不是在每一端都有点标签,而是计算中心并只放置一个标签。

所以在 jqplot.pointlabels.js 中,第 322 行将是:

            if (p.centerLabel) {
                var ell =  xax.u2p(pd[i][0]) + ((xax.u2p(pd[1][0]) - xax.u2p(pd[0][0])) / 2) +p.xOffset(elem, location);
            } else {
                var ell = xax.u2p(pd[i][0]) + p.xOffset(elem, location);    
            }

在 jqplot 的选项中,我会写如下内容:

  pointLabels:{
              show:true,
              location:'s',
              fontSize: '1em',
              centerLabel: true, // extra option, see code
              labelsFromSeries: true,
              formatter: $.jqplot.DefaultTickFormatter,
          }

我可以将所有代码复制到一个名为 jqplot.singleSeriesLabels.js 的新插件中,但是如何让 jqplot 将该插件用于“pointLabels”?

4

1 回答 1

0

我找到了一个简单的解决方案:我将完整的插件复制到一个新文件中,然后像这样更改了插件名称

$.jqplot.newPluginName = function(options) {

在我用来设置 pointLabels 插件选项的网站上,我现在做同样的事情,但使用了新名称:

newPluginName:{
          show:true,
          location:'s',
          fontSize: '1em',
          centerLabel: true, // extra option, see code
          labelsFromSeries: true,
          formatter: $.jqplot.DefaultTickFormatter,
      }

不要忘记在您的网站上包含新的插件文件

于 2012-08-22T09:24:50.340 回答