chart.js - Load ChartJS via VueJS - ChartJS empty and 0px dimension -


alright, trying create chartjs instance via vuejs update data via ajax requests inside component.

basically working, chartjs instance gets created empty , has height , width of 0 , when resize via console still empty.

so best way of creating "chartjs component" vuejs or fault in code below?


the basic way want load chart this.

<chart :resource="'https://httpbin.org/get'"></chart> 

this basic component

var vue = require('vue');  vue.component('chart', {     template: require('./template.html'),     props: ['resource'],     data: function() {         return {             startingdata: {},             latestlabel: {},         }     },     ready: function() {         // here load js data , set startingdata     }, }); 

this directive use pass down data component. way this.el can context of it

vue.directive('loaddata', function(value) {     var startingdata = {             labels: [1, 2, 3, 4, 5, 6, 7],             datasets: [{                 fillcolor: "rgba(151,187,205,0.2)",                 strokecolor: "rgba(151,187,205,1)",                 pointcolor: "rgba(151,187,205,1)",                 pointstrokecolor: "#fff",                 data: [28, 48, 40, 19, 86, 27, 90]             }]         },         latestlabel = startingdata.labels[6];      var livechart = new chart(this.el.getcontext('2d')).bar(startingdata);      setinterval(function() {         livechart.adddata([math.random() * 100], ++latestlabel);         livechart.removedata();     }, 1000); }); 

this template of component

<canvas width="960" height="300" v-load-data="startingdata"></canvas> 

you concerned this issue. graph not render because, pointed out, graph has height , width of 0. had this problem while working tabsets, , solved redrawing graph directive :

app.directive('graphcanvasrefresh', ['$compile', function($compile) { function link(scope, elem, attrs) {  function refreshdom() {     var markup = '<canvas class="chart chart-pie" id="graph" data="entitygraph.data" labels="entitygraph.labels" legend="true" colours="graphcolours" ></canvas>';     var el = angular.element(markup);     compiled = $compile(el);     elem.html('');     elem.append(el);     compiled(scope); };  // refresh dom when attribute value changed scope.$watch(attrs.graphcanvasrefresh, function(value) {     refreshdom(); });  // clean dom on destroy scope.$on('$destroy', function() {     elem.html(''); }); };    return  {    link: link  }; }]); 

hope can you


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

android - Go back to previous fragment -