Dynamic bar chart: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) No edit summary |
A WASSERMANN (talk | contribs) No edit summary |
||
(6 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
<jsxgraph width="700" height="600" box="box"> | <jsxgraph width="700" height="600" box="box"> | ||
board = JXG.JSXGraph.initBoard('box', { | board = JXG.JSXGraph.initBoard('box', {boundingbox: [-1, 9, 13, -3], axis:true}); | ||
board.suspendUpdate(); | board.suspendUpdate(); | ||
var s = board. | var s = board.create('slider', [[1,8],[4,8],[1,1,1.5]], {name:'S',strokeColor:'black',fillColor:'white'}); | ||
var f = [function(){return (s.Value()*4.5).toFixed(2);}, | var f = [function(){return (s.Value()*4.5).toFixed(2);}, | ||
function(){return (s.Value()*(-1)).toFixed(2);}, | function(){return (s.Value()*(-1)).toFixed(2);}, | ||
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 | var colors = ['#8E1B77','#BE1679','#DC1765','#DA2130','#DB311B','#DF4917','#E36317','#E87F1A','#F1B112','#FCF302','#C1E212']; | ||
var chart = board.create('chart', [f], { | |||
chartStyle:'bar', | |||
var dataArr = [4,1,3,2,5,6.5,1.5,2,0.5,1.5,-1]; | width:0.8, | ||
var chart2 = board. | labels:f, | ||
chart2[0].setProperty('strokeColor:black','strokeWidth: | colorArray: colors, | ||
for(var i=0; i<11;i++) { | shadow:true | ||
chart2[1][i].setProperty({strokeColor:'black',fillColor:'white',face:'[]', size:4, strokeWidth: | }); | ||
var leg = board.create('legend', [10, 8.5], {labels: f, colorArray: colors}); | |||
var dataArr = [4,1,3,2,5,6.5,1.5,2,0.5,1.5,-1]; | |||
var chart2 = board.create('chart', dataArr, {chartStyle:'line,point'}); | |||
chart2[0].setProperty('strokeColor:black','strokeWidth:2','shadow:true'); | |||
for (var i=0; i<11;i++) { | |||
chart2[1][i].setProperty({strokeColor:'black',fillColor:'white',face:'[]', size:4, strokeWidth:2}); | |||
} | } | ||
board.unsuspendUpdate(); | board.unsuspendUpdate(); | ||
Line 31: | Line 39: | ||
===The JavaScript code=== | ===The JavaScript code=== | ||
<source lang=" | <source lang="javascript"> | ||
board = JXG.JSXGraph.initBoard('box', {boundingbox: [-1, 9, 13, -3], axis:true}); | |||
board = JXG.JSXGraph.initBoard('box', { | |||
board.suspendUpdate(); | board.suspendUpdate(); | ||
var s = board. | var s = board.create('slider', [[1,8],[4,8],[1,1,1.5]], {name:'S',strokeColor:'black',fillColor:'white'}); | ||
var f = [function(){return (s.Value()*4.5).toFixed(2);}, | var f = [function(){return (s.Value()*4.5).toFixed(2);}, | ||
function(){return (s.Value()*(-1)).toFixed(2);}, | function(){return (s.Value()*(-1)).toFixed(2);}, | ||
Line 49: | Line 56: | ||
function(){return (s.Value()*(-1.25)).toFixed(2);} | function(){return (s.Value()*(-1.25)).toFixed(2);} | ||
]; | ]; | ||
var | var colors = ['#8E1B77','#BE1679','#DC1765','#DA2130','#DB311B','#DF4917','#E36317','#E87F1A','#F1B112','#FCF302','#C1E212']; | ||
var chart = board.create('chart', [f], { | |||
chartStyle:'bar', | |||
width:0.8, | |||
labels:f, | |||
colors: colors, | |||
shadow:true | |||
}); | |||
var leg = board.create('legend', [10, 8.5], {labels: f, colorArray: colors}); | |||
var dataArr = [4,1,3,2,5,6.5,1.5,2,0.5,1.5,-1]; | var dataArr = [4,1,3,2,5,6.5,1.5,2,0.5,1.5,-1]; | ||
var chart2 = board. | var chart2 = board.create('chart', dataArr, {chartStyle:'line,point'}); | ||
chart2[0].setProperty('strokeColor:black','strokeWidth: | chart2[0].setProperty('strokeColor:black','strokeWidth:2','shadow:true'); | ||
for(var i=0; i<11;i++) { | for (var i=0; i<11;i++) { | ||
chart2[1][i].setProperty({strokeColor:'black',fillColor:'white',face:'[]', size:4, strokeWidth: | chart2[1][i].setProperty({strokeColor:'black',fillColor:'white',face:'[]', size:4, strokeWidth:2}); | ||
} | } | ||
board.unsuspendUpdate(); | board.unsuspendUpdate();</source> | ||
</source> | |||
[[Category:Examples]] | [[Category:Examples]] | ||
[[Category:Charts]] | [[Category:Charts]] |
Latest revision as of 12:42, 12 March 2020
The JavaScript code
board = JXG.JSXGraph.initBoard('box', {boundingbox: [-1, 9, 13, -3], axis:true});
board.suspendUpdate();
var s = board.create('slider', [[1,8],[4,8],[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 colors = ['#8E1B77','#BE1679','#DC1765','#DA2130','#DB311B','#DF4917','#E36317','#E87F1A','#F1B112','#FCF302','#C1E212'];
var chart = board.create('chart', [f], {
chartStyle:'bar',
width:0.8,
labels:f,
colors: colors,
shadow:true
});
var leg = board.create('legend', [10, 8.5], {labels: f, colorArray: colors});
var dataArr = [4,1,3,2,5,6.5,1.5,2,0.5,1.5,-1];
var chart2 = board.create('chart', dataArr, {chartStyle:'line,point'});
chart2[0].setProperty('strokeColor:black','strokeWidth:2','shadow:true');
for (var i=0; i<11;i++) {
chart2[1][i].setProperty({strokeColor:'black',fillColor:'white',face:'[]', size:4, strokeWidth:2});
}
board.unsuspendUpdate();