I am using a switch-statement to switch between modes on a the jqPlot jQuery plugin.
How can I apply my value from the switch to the function parameters?
I have
type = detectType(gType);
I need this to display, where type is in the parameters below. It does not return that value:
function detectType(value){
switch(value){
case 'bar':
return 'renderer:$.jqplot.BarRenderer,';
break;
case 'pie':
return 'renderer: $.jqplot.PieRenderer,';
break;
}
}
function generateGraph(id,gType) {
type = detectType(gType);
var s1 = [2, 6, 7, 10];
var s2 = [7, 5, 3, 4];
var s3 = [14, 9, 3, 8];
$.jqplot(''+id+'', [s1, s2, s3], {
stackSeries: true,
captureRightClick: true,
seriesDefaults: {
type
rendererOptions: {
barMargin: 30,
highlightMouseDown: true
},
pointLabels: {
show: true
}
},
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer
},
yaxis: {
padMin: 0
}
},
legend: {
show: true,
location: 's',
placement: 'outside'
}
});
}
You can’t do what you’re trying to do with the
typestring. It’s invalid syntax.Instead,
detectTypeshould just return the renderer object itself, not as a string. Then, assign that torendererin your series defaults. Like so:Then: