forked from apertureless/vue-chartjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(charts): Export generateChart to create custom charts
- Loading branch information
1 parent
bfda218
commit 50e5644
Showing
3 changed files
with
69 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Chart from 'chart.js' | ||
import { generateChart } from '../BaseCharts' | ||
|
||
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) { | ||
let activePoint = this.chart.tooltip._active[0] | ||
let ctx = this.chart.ctx | ||
let x = activePoint.tooltipPosition().x | ||
let topY = this.chart.scales['y-axis-0'].top | ||
let 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() | ||
} | ||
} | ||
}) | ||
|
||
const LineWithLine = generateChart('line-with-chart', 'LineWithLine') | ||
|
||
export default { | ||
extends: LineWithLine, | ||
mounted () { | ||
this.renderChart({ | ||
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'], | ||
datasets: [ | ||
{ | ||
label: 'Data One', | ||
backgroundColor: '#f87979', | ||
data: [40, 39, 10, 40, 39, 80, 40] | ||
} | ||
] | ||
}, { | ||
responsive: true, | ||
maintainAspectRatio: false, | ||
tooltips: { | ||
intersect: false | ||
} | ||
}) | ||
} | ||
} |