Page 1 of 1
Change scale of Administration Statistics graph?
Posted: Fri Sep 04, 2009 10:59 pm
by bandergrove
I love the Administration Statistics graph feature, but the y-axis (number of sales) is set by default at 100. Is it possible to change this value?
The website I'm setting up has nowhere near 100 sales per day (and will not for the forseeable future), so it would be nice to have a graph that better fits the data set. I estimate we will get a maximum of 10 sales / day...so I'd like to have the graph go up only to 15 or 20.
Thoughts?
Re: Change scale of Administration Statistics graph?
Posted: Mon Sep 07, 2009 11:22 am
by Blueforce
Hi there!
I think you can do it by adding a range value to the function report()
You can find this function in file home.php in folder: \admin\controller\common\
The function starts at line 113 in a standard OpenCart v1.3.2.
You add the range valu like this:
&chxr=1,START,END
So, if you want a scale from 0-30 it should look like this:
&chxr=1,0,30
The code starting at line 113 should then look like this:
public function report() {
$this->load->language('common/home');
$url = 'http://chart.apis.google.com/chart?cht=lc';
$url .= '&chdl=' . $this->language->get('text_order') . '|' . $this->language->get('text_customer');
$url .= '&chco=FF0000,00FF00';
$url .= '&chs=838x330';
$url .= '&chxr=1,0,30'; //Added for Custom Scale
$url .= '&chxt=x,y';
$url .= '&chg=0,10';
But the best way is to add the custom scale line in the different cases for day, week, month and year.
If you scroll down from line 113 you find the case switches for each range. Add the appropriate scale for each time period. You can add the line:
$url .= '&chxr=1,0,XX'; //Add for custom scale
before the each:
$url .= '&chxl=0:|' . implode('|', $labels) . '|';
I hope this helps you!
Regards,
Leffe
Re: Change scale of Administration Statistics graph?
Posted: Mon Sep 07, 2009 12:53 pm
by Blueforce
just a thought....
You could also add a automatic max value for the scale, maybe to the nearest higher 10.
It could be done with something like this:
$url .= '&chxr=1,0,' . round(ceil((max(max($orders),max($customers))/10)))*10; //Add for custom Auto scale
It compares the orders and customers and pulls the highest value and rounds it to the nearest higher 10.
There are probably a cleaner nicer way to do it....
Regards,
Leffe
Re: Change scale of Administration Statistics graph?
Posted: Mon Sep 07, 2009 6:34 pm
by Blueforce
A heads up!
I have just run this on a test install of Open Cart and it does not wor as supposed... the drawn scale is still devided by100! I will look in to how this can/should be configured.
/Leffe
Re: Change scale of Administration Statistics graph?
Posted: Wed Sep 09, 2009 1:15 am
by bandergrove
Thanks so much for looking into this! I really appreciate it.

Re: Change scale of Administration Statistics graph?
Posted: Wed Sep 09, 2009 1:54 pm
by Blueforce
Hi there,
Now I think I have something working!
I also added a few other scale calculations...
You need to add a few lines near the bottom of the file "home.php" in folder: \admin\controller\common\
Add the lines just before:
$this->response->setOutput($url);
Like this:
//Add for Custom Auto Scale
$scale = max(10,round(ceil((max(max($orders),max($customers))/10)))*10);
if($scale < 11 ) {$step= 1;}
else if($scale > 10 && $scale < 31) {$step= 2;}
else if($scale > 30 && $scale < 101) {$step= 5;}
else if($scale > 100 && $scale < 201) {$step= 10;}
else if($scale > 200 && $scale < 401) {$step= 20;}
else if($scale > 400 && $scale < 1001) {$step= 50;}
else if($scale > 1000 ) {$step= 100;}
else {$step = 0;}
if($this->request->get['range'] == 'day') {
$lineh = 100/24;
} else if($this->request->get['range'] == 'week') {
$lineh = 100/7;
} else if($this->request->get['range'] == 'month') {
$lineh = 100/(date('j', mktime(23, 59, 59, date('m'), 0, date('Y'))));
} else if($this->request->get['range'] == 'year') {
$lineh = 100/12;
} else {
$lineh = 10;
}
$url .= '&chds=0,'.$scale;
$url .= '&chxr=1,0,'.$scale.','.$step.'&chg='.$lineh.',10';
//Add for Custom Auto Scale END
$this->response->setOutput($url);
I hope it does the trick for you!
/Leffe
Re: Change scale of Administration Statistics graph?
Posted: Fri Mar 12, 2010 8:03 am
by jtsroberts
Nice once Leffe, that works perfectly for me (v 1.3.4)