var chart_xaxis_idx=-1,chart_series,chart_series_index=-1,temp_chart_title;
$(document).ready(function(){function a(){b.chart.width=$("#resizer").width()-20;b.chart.height=$("#resizer").height()-20;f!=null&&f.destroy();f=PMA_queryChart(d,c,b)}var f=null,d=jQuery.parseJSON($("#querychart").html());chart_series="columns";chart_xaxis_idx=$('select[name="chartXAxis"]').attr("value");$("#resizer").resizable({minHeight:240,minWidth:300});$("#resizer").bind("resizestop",function(){$("#querychart").height($("#resizer").height()*0.96);$("#querychart").width($("#resizer").width()*
0.96);f.replot({resetAxes:true})});var b={chart:{type:"line",width:$("#resizer").width()-20,height:$("#resizer").height()-20}},c={grid:{drawBorder:false,shadow:false,background:"rgba(0,0,0,0)"},axes:{xaxis:{label:$('input[name="xaxis_label"]').val(),labelRenderer:$.jqplot.CanvasAxisLabelRenderer},yaxis:{label:$('input[name="yaxis_label"]').val(),labelRenderer:$.jqplot.CanvasAxisLabelRenderer}},title:{text:$('input[name="chartTitle"]').attr("value")},legend:{show:true,placement:"outsideGrid",location:"se"}};
$("#querychart").html("");$('input[name="chartType"]').click(function(){b.chart.type=$(this).attr("value");a();$(this).attr("value")=="bar"||$(this).attr("value")=="column"?$("span.barStacked").show():$("span.barStacked").hide()});$('input[name="barStacked"]').click(function(){this.checked?$.extend(true,c,{stackSeries:true}):$.extend(true,c,{stackSeries:false});a()});$('input[name="chartTitle"]').focus(function(){temp_chart_title=$(this).val()});$('input[name="chartTitle"]').keyup(function(){$(this).attr("value");
c.title=$('input[name="chartTitle"]').val();a()});$('input[name="chartTitle"]').blur(function(){$(this).val()!=temp_chart_title&&a()});$('select[name="chartXAxis"]').change(function(){chart_xaxis_idx=this.value;a()});$('select[name="chartSeries"]').change(function(){chart_series=this.value;chart_series_index=this.selectedIndex;a()});$('input[name="xaxis_label"]').keyup(function(){c.axes.xaxis.label=$(this).attr("value");a()});$('input[name="yaxis_label"]').keyup(function(){c.axes.yaxis.label=$(this).attr("value");
a()});a();$("#querychart").show()});function in_array(a,f){for(var d=0;d<f.length;d++)if(f[d]==a)return true;return false}
function PMA_queryChart(a,f,d){if($("#querychart").length!=0){var b=[],c=[];$.each(a[0],function(h){b.push(h)});switch(d.chart.type){case "column":case "spline":case "line":case "bar":for(var i=0,e=0;e<b.length;e++)if(e!=chart_xaxis_idx){c[i]=[];if(chart_series=="columns"||chart_series==b[e]){$.each(a,function(h,g){c[i].push([g[b[chart_xaxis_idx]],parseFloat(g[b[e]])])});i++}}break;case "pie":if(chart_series!="columns"){c[0]=[];$.each(a,function(h,g){c[0].push([g[b[chart_xaxis_idx]],parseFloat(g[chart_series])])})}}a=
{title:{text:""}};if(d.chart.type=="line")a.axes={xaxis:{},yaxis:{}};if(d.chart.type=="bar"){a.seriesDefaults={renderer:$.jqplot.BarRenderer,rendererOptions:{barDirection:"vertical",highlightMouseOver:true}};a.axes={xaxis:{renderer:$.jqplot.CategoryAxisRenderer},yaxis:{}}}if(d.chart.type=="spline")a.seriesDefaults={rendererOptions:{smooth:true}};if(d.chart.type=="pie")a.seriesDefaults={renderer:$.jqplot.PieRenderer,rendererOptions:{showDataLabels:true,highlightMouseOver:true,showDataLabels:true,dataLabels:"value"}};
$.extend(true,a,f);a.series=[];for(e=0;e<b.length;e++)if(parseInt(chart_xaxis_idx)!=e)if(chart_series=="columns"||chart_series==b[e])a.series.push({label:b[e]});return $.jqplot("querychart",c,a)}};
