UNPKG

primevue

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primevue.svg)](https://badge.fury.io/js/primevue) [![Discord Chat](https://img.shields.io/discord/55794023

2 lines (1 loc) 1.63 kB
import{openBlock as t,createBlock as e,createVNode as i}from"vue";var a={name:"Chart",emits:["select"],props:{type:String,data:null,options:null,width:{type:Number,default:300},height:{type:Number,default:150}},chart:null,mounted(){this.initChart()},beforeUnmount(){this.chart&&(this.chart.destroy(),this.chart=null)},watch:{data(){this.reinit()},type(){this.reinit()},options(){this.reinit()}},methods:{initChart(){import("chart.js").then((t=>{t&&t.default&&(this.chart=new t.default(this.$refs.canvas,{type:this.type,data:this.data,options:this.options}))}))},getCanvas(){return this.$canvas},getBase64Image(){return this.chart.toBase64Image()},refresh(){this.chart&&this.chart.update()},reinit(){this.chart&&(this.chart.destroy(),this.initChart())},onCanvasClick(t){if(this.chart){const e=this.chart.getElementAtEvent(t),i=this.chart.getDatasetAtEvent(t);e&&e[0]&&i&&this.$emit("select",{originalEvent:t,element:e[0],dataset:i})}},generateLegend(){if(this.chart)return this.chart.generateLegend()}}};const n={class:"p-chart"};!function(t,e){void 0===e&&(e={});var i=e.insertAt;if(t&&"undefined"!=typeof document){var a=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css","top"===i&&a.firstChild?a.insertBefore(n,a.firstChild):a.appendChild(n),n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t))}}("\n.p-chart {\n position: relative;\n}\n"),a.render=function(a,h,s,r,c,d){return t(),e("div",n,[i("canvas",{ref:"canvas",width:s.width,height:s.height,onClick:h[1]||(h[1]=t=>d.onCanvasClick(t))},null,8,["width","height"])])};export default a;