<?php
 
$graphAjax = "/statview/_ajax/ajax.graph.php";

$idQ = $_GET['id'];
$idP = $_GET['idProject'];
$type = $_GET['type'];

if(isset($_GET['qIdCross'])){
	$idQcross = $_GET['qIdCross'];	
}

?>

var graf;

//inicialnizacija grafa
function ChartInit() 
{
	graf = new Highcharts.Chart({
		chart: {
			renderTo: 'container',
            backgroundColor: '#F6F5F0'
            //zoomType: 'xy'
        },

	    title: {
	        text: ''
	    },
	    
	    xAxis: {
	    	categories: [],
	        allowDecimals: true,
	        gridLineDashStyle: 'shortdash',
	        tickmarkPlacement: 'on',
	        title: {
	    		text: ''
	    	},
	        labels: {
	            align: 'center',
	            y: 30,
	            style: {
					fontWeight: 'bold',
					fontSize: '12px',
					padding: '8px'
				}
	        }
	    },
	    
	    yAxis: {
		    gridLineWidth: 0,
	        title: { 
	        	text: '' 
	    	},
	        allowDecimals: true,
	        labels: {
	        	enabled: false
	        }	
	    },
	    
	    tooltip: {
    	    
        },
        
        plotOptions: {
		   pie: {
	            allowPointSelect: true,
	            cursor: 'pointer',
	            dataLabels: {
	                enabled: false
	            },
	            showInLegend: true
	       },
	       
	       column: {
				pointPadding: 0,
				borderWidth: 0
           }
		},
	    
	    legend: {
	        align: 'right',
	        floating: true,
	        layout: 'vertical',
	        verticalAlign: 'top',
	        borderWidth: 0,
	        itemStyle: {
	            color: '#000000',
	            fontSize: '15px'
	        }
	    },
	           
	    credits: {
	    	enabled: false
		},
		
		navigation: {
            buttonOptions: {
                enabled: false
            }
        },
		
		series: [],
		
		//nastavitve za pie graf
		pieSettings:function(){
	    	graf.optionsMarginBottom = 60;
	    	graf.optionsMarginRight = 330;
	    	graf.tooltip.options.pointFormat = "<b>{point.percentage:.1f}%</b>";
	    	graf.legend.options.labelFormatter = function() {
	            return this.name +' <b>'+ parseFloat(this.y).toFixed(1) + '%</b>';
	        };
	    	graf.render();
	   },
	    
	    //nastavitve za column graf
		columnSettings:function(){
	    	graf.optionsMarginTop = 30;
	    	graf.optionsMarginRight = 200;
	    	graf.options.xAxis[0].gridLineWidth = 0;
	    	graf.tooltip.options.pointFormat = "<span style='font-size:10px'>{point.key}</span><table><tr><td style='color:{series.color}; padding:0'>{series.name}: </td><td style='padding:0'><b>{point.y:.1f}%</b></td></tr></table>";
	    	graf.render();
	    },
	    
	    //nastavitve za line graf
		lineSettings:function(){
	    	graf.optionsMarginTop = 30;
	    	graf.options.xAxis[0].gridLineWidth = 1;
	    	graf.tooltip.options.pointFormat = "<span style='font-size:10px'>{point.key}</span><table><tr><td style='color:{series.color}; padding:0'>{series.name}: </td><td style='padding:0'><b>{point.y:.1f}%</b></td></tr></table>";
	    	graf.render();
	    },
	    
	    removeAllSeries : function()
	    {
	        while(graf.t.series.length > 0)
                chart.series[0].remove(true);
	    }
	});	 
}

function LoadData() 
{
	$.ajax({
		url: '<?php echo $graphAjax; ?>', 
		type: 'POST',
		data : 'type=<?php echo $type; ?>&id=<?php echo $idQ; ?>&idProject=<?php echo $idP; ?>&idQcross=<?php echo $idQcross; ?>', 
		success: function(data){	
			if(data) eval(data);
		}
	});


	
}

ChartInit();
LoadData();
