2

我是 Chart.js 和 ng2-charts 的新手。我希望在 ng2-charts 中重写 chart.js 中的这个功能。它甚至可能吗?

Chart.defaults.LineWithLine = Chart.defaults.line;
Chart.controllers.LineWithLine = Chart.controllers.line.extend({
  draw: function(ease) {
     Chart.controllers.line.prototype.draw.call(this, ease);

     if (this.chart.tooltip._active && this.chart.tooltip._active.length) {
      var activePoint = this.chart.tooltip._active[0],
          ctx = this.chart.ctx,
          x = activePoint.tooltipPosition().x,
          topY = this.chart.scales['y-axis-0'].top,
          bottomY = this.chart.scales['y-axis-0'].bottom;

       // draw line
       ctx.save();
       ctx.beginPath();
       ctx.moveTo(x, topY);
       ctx.lineTo(x, bottomY);
       ctx.lineWidth = 2;
       ctx.strokeStyle = '#07C';
       ctx.stroke();
       ctx.restore();
     }
  }
});

这是我的小提琴:https ://jsfiddle.net/haq5k2mw/

4

1 回答 1

2

您可以改用剪贴板

下载:https ://zenorocha.github.io/clipboard.js/

您现在可以使用此方法:(需要 jquery)

在您的 html 头中添加:

<script src="dist/clipboard.min.js"></script>

在您的 html 代码中添加:

<pre class="copytoclipboard">
    <code class="language-html">
        <h1>Hello world !</h1>
    </code>
</pre>

在您的页脚中添加:

<script>
        /* Prism copy to clipbaord for all pre with copytoclipboard class */
        $('pre.copytoclipboard').each(function () {
            $this = $(this);
            $button = $('<button>Copy</button>');
            $this.wrap('<div/>').removeClass('copytoclipboard');
            $wrapper = $this.parent();
            $wrapper.addClass('copytoclipboard-wrapper').css({position: 'relative'})
            $button.css({position: 'absolute', top: 10, right: 10}).appendTo($wrapper).addClass('copytoclipboard btn btn-default');
            /* */
            var copyCode = new Clipboard('button.copytoclipboard', {
                target: function (trigger) {
                    return trigger.previousElementSibling;
                }
            });
            copyCode.on('success', function (event) {
                event.clearSelection();
                event.trigger.textContent = 'Copied';
                window.setTimeout(function () {
                    event.trigger.textContent = 'Copy';
                }, 2000);
            });
            copyCode.on('error', function (event) {
                event.trigger.textContent = 'Press "Ctrl + C" to copy';
                window.setTimeout(function () {
                    event.trigger.textContent = 'Copy';
                }, 2000);
            });
        });
</script>

基于:http ://webdesign.tutsplus.com/tutorials/copy-to-clipboard-made-easy-with-clipboardjs--cms-25086

于 2015-12-10T09:34:07.527 回答