Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working with npm #185

Open
franckysolo opened this issue Dec 3, 2016 · 1 comment
Open

Not working with npm #185

franckysolo opened this issue Dec 3, 2016 · 1 comment

Comments

@franckysolo
Copy link

franckysolo commented Dec 3, 2016

hello,
I'am trying to use your plugin in a Vuejs project but i' can't make it work, a error appear :
Cannot read property 'appendChild' of undefined
the error come from your CanvasRenderer class:

var CanvasRenderer = function(el, options) {
var cachedBackground;
	var canvas = document.createElement('canvas');

	el.appendChild(canvas);  // here

The component vue:

<template lang="html">
  <div class="easypiechart"
    :data-percent="percent" :data-size="size"
    :data-bar-color="color" data-scale-color="false"
    data-line-cap="round" data-line-width="4"
    :style="'width: ' + size + 'px; height: ' + size + 'px;'">
    <i :class="icon" class="fa fa-4x" :style="'line-height: ' + size + 'px;'"></i>
    <p class="text-uppercase text-lg mt-20 mb-0">
      <strong :class="className">{{ count }}</strong>
      <small class="text-md text-light text-default lt">{{ title }}</small>
    </p>
    <p class="text-light">
      <i class="fa fa-caret-down text-warning"></i>
      {{ percent }}% ce mois-ci
    </p>
    <canvas :height="size" :width="size"></canvas>
  </div>
</template>

<script>
import $ from 'jquery'
$.fn.easyPieChart = require('easy-pie-chart')
export default {
  props: ['count', 'percent', 'color', 'title', 'size', 'icon', 'className'],
  mounted () {
    $('.easypiechart').easyPieChart()
    this.$nextTick(() => {
      $('.easypiechart').data('easyPieChart').update(this.percent)
    })
  }
}
</script>
@jmarceli
Copy link

I was having a similar problem. The probable cause is calling .easyPieChart() on an element which is not a jQuery object. Maybe you should wait for $(document).ready(..) ? (I don't know VueJS so I can't give you exact answer).
In your case I would check the $('.easypiechart') value.

Aside note: It is possible to import jquery easy-pie-chart with:

import 'easy-pie-chart/dist/jquery.easypiechart';

Which is for me more elegant way of using it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants