chart.js - 在ng2-charts中重写chart.js功能

标签 chart.js ng2-charts

我是 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();
     }
  }
});

这是我的 fiddle :https://jsfiddle.net/haq5k2mw/

最佳答案

您可以使用clipboardjs代替

下载: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

关于chart.js - 在ng2-charts中重写chart.js功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29040192/

相关文章:

chart.js - ng2-charts:如何设置 y 轴的固定范围

javascript - Chartjs 的多个气泡图数据集

javascript - 无法在 Chart.js 上显示数据

javascript - 图表未根据从 Jquery 收到的值进行更新

angular - 在 ng2-charts 中自定义图例形状

angular - ng2-charts 条形图不显示数据/图形标签

Angular 2 ng2-charts donut 文字在中间?

angular - 如何使用 ng2 图表在圆环图中显示标签?

javascript - Chart.js 水平条宽度

javascript - 如何使用 vue-chartjs 将图像添加到图表标签?