【问题标题】:Re-write chart.js functionality in ng2-charts在 ng2-charts 中重写 chart.js 功能
【发布时间】:2015-05-16 09:43:07
【问题描述】:

我是 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/

【问题讨论】:

    标签: chart.js ng2-charts


    【解决方案1】:

    你可以使用 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-03
      • 2016-05-27
      • 2017-02-23
      • 1970-01-01
      相关资源
      最近更新 更多