我是图表.js和ng2-charts的新手。我希望图表中的此功能.js在ng2图表中重写。 甚至有可能吗?
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/
你可以改用剪贴板js
下载它: 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