0

There is a jquery function which passes value to the donut chart and updates the chart when function is called.but i want to call the jquery function in coffee script.

how can i do that?

Here's what i have tried.i am getting error Uncaught ReferenceError: get_data1 is not defined

script.js

$( document ).ready(function() {
            function get_data() {
              var props = ["Slice1","Slice2","Slice3"];
              var out   = [];
              //for (var i = 0; i <= 6; i++) {
                out.push({"name":props[1], "hvalue": 30});
                out.push({"name":props[2], "hvalue": 20});
                out.push({"name":props[3], "hvalue": 50});
              //};
              return out;
            }

            function get_data1() {
              var props = ["Slice1","Slice2","Slice3"];
              var out   = [];
              //for (var i = 0; i <= 6; i++) {
                out.push({"name":props[1], "hvalue": 50});
                out.push({"name":props[2], "hvalue": 40});
                out.push({"name":props[3], "hvalue": 10});
              //};
              return out;
            }
            $(".exp").donutpie();
            $(".exp").donutpie('update', get_data());                               

            $(".exp").donutpie('update', get_data1());       //I need to call this on coffee script

          });

App.coffee

sketchlayer = new Layer
    width:400
    height:400
    x:426
    y:126
    backgroundColor: ""
    opacity: 1

sketchlayer.html = "<div class='exp' width='315' height='315'></div>"

buttonlayer = new Layer
    width:100
    height:40
    backgroundColor:"red"

buttonlayer.onClick -> $(".exp").donutpie('update', get_data1());
CJAY
  • 6,989
  • 18
  • 64
  • 106
  • 1
    can you try bringing the the function `function get_data() { }` and `function get_data1() { }` outside of `$(document).ready` block. I think that should work. – vijayP Sep 29 '16 at 04:40
  • @ vijay i tried it already, but its not working.i'm getting Cannot read property 'select' of undefined error – CJAY Sep 29 '16 at 04:53
  • 1
    Move just the two function definitions (`get_data` and `get_data1`) out of the `$(document).ready(...)`, the three `#('.exp')` lines need to stay where they are. – mu is too short Sep 29 '16 at 05:30

0 Answers0