Dynamic bar chart: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
Line 14: Line 14:
         function(){return (s.Value()*3.5).toFixed(2);},
         function(){return (s.Value()*3.5).toFixed(2);},
         function(){return (s.Value()*2).toFixed(2);},
         function(){return (s.Value()*2).toFixed(2);},
         function(){return (s.Value()*(-1.25)).toFixed(2);},
         function(){return (s.Value()*(-1.25)).toFixed(2);}
         ];
         ];
var chart = board.createElement('chart', [f],  
var chart = board.createElement('chart', [f],  
Line 47: Line 47:
         function(){return (s.Value()*3.5).toFixed(2);},
         function(){return (s.Value()*3.5).toFixed(2);},
         function(){return (s.Value()*2).toFixed(2);},
         function(){return (s.Value()*2).toFixed(2);},
         function(){return (s.Value()*(-1.25)).toFixed(2);},
         function(){return (s.Value()*(-1.25)).toFixed(2);}
         ];
         ];
var chart = board.createElement('chart', [f],  
var chart = board.createElement('chart', [f],  

Revision as of 13:50, 13 January 2010

The JavaScript code

<jsxgraph width="700" height="600" box="box">
board = JXG.JSXGraph.initBoard('box', {originX: 50, originY: 450, unitX: 50, unitY: 50, axis:true});
board.suspendUpdate();           

var s = board.createElement('slider', [[8,7],[11,7],[1,1,1.5]], {name:'S',strokeColor:'black',fillColor:'white'});
var f = [function(){return (s.Value()*4.5).toFixed(2);},
         function(){return (s.Value()*(-1)).toFixed(2);},
         function(){return (s.Value()*3).toFixed(2);},
         function(){return (s.Value()*2).toFixed(2);},
         function(){return (s.Value()*(-0.5)).toFixed(2);},
         function(){return (s.Value()*5.5).toFixed(2);},
         function(){return (s.Value()*2.5).toFixed(2);},
         function(){return (s.Value()*(-0.75)).toFixed(2);},
         function(){return (s.Value()*3.5).toFixed(2);},
         function(){return (s.Value()*2).toFixed(2);},
         function(){return (s.Value()*(-1.25)).toFixed(2);}
        ];
var chart = board.createElement('chart', [f], 
        {chartStyle:'bar', width:0.8, labels:f,
         colorArray:['#8E1B77','#BE1679','#DC1765','#DA2130','#DB311B','#DF4917','#E36317','#E87F1A','#F1B112','#FCF302','#C1E212'], shadow:true});
            
var dataArr = [4,1,3,2,5,6.5,1.5,2,0.5,1.5,-1];            
var chart2 = board.createElement('chart', dataArr, {chartStyle:'line,point'});
chart2[0].setProperty('strokeColor:black','strokeWidth:2pt','shadow:true');
for(var i=0; i<11;i++) {
    chart2[1][i].setProperty({strokeColor:'black',fillColor:'white',face:'[]', size:4, strokeWidth:'2pt'});
}
board.unsuspendUpdate();
</jsxgraph>