Sorry for this based question. I am fresh to jqplot and would like to use it to generate a bar graph based on data calculated from a function.
Now, I have a parameter which holds data. Also, I have simple codes to generate a bar plot. So, can anyone give me a hint on how to link these two pieces together?
Thanks!
Here is the code:
x_data=function(a,b,c,d)
#this is the data generated from a function and it needs to be
#sent to jqplot function, i.e., x_data=[165.33, 102.9, 89.04, 181.54, 114.92].
#In order to pass the parameter to jqplot, do I need to print it out in the HTML?
<script type='text/javascript'>
$(document).ready(function(x_data){
$.jqplot.config.enablePlugins = true;
var s1=x_data; //I need to find a way to link s1 to x_data
$.jqplot('chart1', [s1], {
seriesDefaults:{
renderer:$.jqplot.BarRenderer,
pointLabels: { show: true },
rendererOptions: {
barWidth: 3
}
}
})
})
</script>
You need to make sure that whatever you are entering as the 2nd parameter of the
$.jqplot()method, in your case it isx_pre_irr, is in the form of, e.g.[[[1,2],[2,3],[3,6],[4,5]],[[1,2],[2,3],[3,6],[4,5]]].You could find more details in the examples here.
EDIT
You have few important errors there:
With bar chart the
CategoryAxisRenderershould be used:To get stuff inside a HTML tag using
jQueryyou usetext()(orhtml())method, not
val()as it returns whatever a tag has in itsvalueparameter.Then whatever you will get will be a String thus you must convert it to array of values, e.g. using
$.parseJSON($('#x_pre_irr_val').text());.This is presented in this sample.