Set javascript variable equal to Storyline variable? -


so i've got javascript pie chart , 5 slices. want implement chart storyline slide. in storyline project i've got 5 variables has got specific values. when user answers questions, these values change. @ end of project these values visualized pie chart.

the pie chart works perfectly, have connect these slices storyline variables. how can this?

here can see how pie chart build.

// gives pie slices name. // var mypersoonlijkheid = {     "categorie1": 10,     "categorie2": 44,     "categorie3": 32,     "categorie4": 12,     "categorie5": 8 

can var=categorie1 numbers are? or more complicated that? i;ve searched on internet answers, couldn't found something, otherwhise wouldn't asking now. haha!

so.. there can me? :d appriciate it! thank you!

i managed make work :d

what did:

i made storyline project have 5 sliders. sliders have each own variable (var1, var2, var3, var4 , var5). created blank slide pie chart going be.

then made index.html file. file contains

<body>      <canvas id="mycanvas"></canvas>     <script type="text/javascript"src="pie-chart.js"></script> </body> 

i saved file map on server.

after put javascript together:

// js code first reference canvas , set width , height. draw on canvas, need reference 2d context contains drawing methods. //         /*global quotes:true, global $*/      window.onload = function() {         var player = window.parent.getplayer(); //this piece missing.//          var mycanvas = document.getelementbyid("mycanvas");         mycanvas.width = 300;         mycanvas.height = 300;         var ctx = mycanvas.getcontext("2d");         // define function. //         function drawline(ctx, startx, starty, endx, endy) {             ctx.beginpath();             ctx.moveto(startx, starty);             ctx.lineto(endx, endy);         }         // function draws arc between lines. //         function drawarc(ctx, centerx, centery, radius, startangle, endangle) {             ctx.beginpath();             ctx.arc(centerx, centery, radius, startangle, endangle);             ctx.stroke();         }         // function draws coloured shape between lines. //         function drawpieslice(ctx, centerx, centery, radius, startangle, endangle, color) {             ctx.fillstyle = color;             ctx.beginpath();             ctx.moveto(centerx, centery);             ctx.arc(centerx, centery, radius, startangle, endangle);             ctx.closepath();             ctx.fill();             /* drawline(_ctx,100,100,200,200);             drawarc(_ctx, 150,150,150, 0, math.pi/3);             drawpieslice(_ctx, 150,150,150, math.pi/2, math.pi/2 + math.pi/4, '#ff0000'); */         }         /* retrieves value of storyline variable             (the 1 between quote symbols). */                 var var1 = player.getvar("var1");                 var var2 = player.getvar("var2");                 var var3 = player.getvar("var3");                 var var4 = player.getvar("var4");                 var var5 = player.getvar("var5");          // gives slices value above. //             var mypersoonlijkheid = {                 "categorie1": var1,                 "categorie2": var2,                 "categorie3": var3,                 "categorie4": var4,                 "categorie5": var5         };         var piechart = function(options) {             this.options = options;             this.canvas = options.canvas;             this.ctx = this.canvas.getcontext("2d");             this.colors = options.colors;             this.draw = function() {                 var total_value = 0;                 var color_index = 0;                 (var categ in this.options.data) {                     var val = this.options.data[categ];                     total_value += val;                 }                 var start_angle = 0;                 (categ in this.options.data) {                     val = this.options.data[categ];                     var slice_angle = 2 * math.pi * val / total_value;                     drawpieslice(this.ctx, this.canvas.width / 2, this.canvas.height / 2, math.min(this.canvas.width / 2, this.canvas.height / 2), start_angle, start_angle + slice_angle, this.colors[color_index % this.colors.length]);                     start_angle += slice_angle;                     color_index++;                 }             }         }         var mypiechart = new piechart({             canvas: mycanvas,             data: mypersoonlijkheid,             colors: ["#f2f2f2", "#b3dcff", "#1b96ff", "#004682", "#002341"]         });         mypiechart.draw();         } 

after published storyline file. , works perfectly!

thanks mustafa help. appriciate :d


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -