<?php
include_once( 'include/ECM/open_flash_chart/ofc-library/open-flash-chart.php' );
include_once('modules/EcmCharts/chartHelper.php');

$s=sum(date("Y"));
$sall=$s['all'];
$sall_pur=$s['all_pur'];
$temp=0;

$w=mysql_query("select id,name from ecmproductcategories where deleted='0' and name!=''");
while($r=mysql_fetch_array($w)){
	$ss=$s[date("Y")];
	
	if($sall>0)$v_s=100*$ss['category_sum_'.$r['id']]/$sall;
	else $v=0;
	if($v_s>$temp)$temp=$v_s;
	$sum_s+=$v_s;
		
	if(($sall-$sall_pur)>0)$v_p=100*($ss['category_sum_'.$r['id']]-$ss['category_pur_sum_'.$r['id']])/($sall-$sall_pur);
	else $v_p=0;
	if($v_p>$temp)$temp=$v_p;
	$sum_p+=$v_p;
	$arr_s[]=array(
		"name"=>repl($r['name']),
		"value"=>$v_s,
	);
	$arr_p[]=array(
		"name"=>repl($r['name']),
		"value"=>$v_p,
	);
}
//$arr_s=multisort($arr_s,array(array('key'=>'value','sort'=>'desc')));
for($i=0;$i<count($arr_s);$i++){
	$data_1[]=$arr_s[$i]['value'];
	$data_2[]=$arr_p[$i]['value'];
	$cats[]=$arr_s[$i]['name'];
}

$g = new graph();

$g->title( 'Sales', '{font-size:20px; color: #000000; margin: 5px; background-color: #ffffff; padding:5px; padding-left: 20px; padding-right: 20px;}' );

$g->bg_colour = '#ffffff';

$g->set_data($data_1);
$g->bar( 75, '#D54C78', '', 10 );
$g->set_data($data_2);
$g->bar( 75, '#3334AD', '', 10 );

$g->attach_to_y_right_axis(2);

$g->x_axis_colour( '#909090', '#ADB5C7' );
$g->y_axis_colour( '#909090', '#ADB5C7' );
$g->y_right_axis_colour( '#164166' );

$g->set_x_labels( $cats );
$g->set_x_label_style( 10, '#000000', 2 );

$g->set_y_max( $temp );

$g->y_label_steps( 20 );
//$g->y_right_label_steps( 5 );

$g->set_y_legend( '', 12, '#736AFF' );
$g->set_y_right_legend( 'Free Ram (MB)' ,12 , '#164166' );

echo $g->render();
?>