fabriceunko Posted April 17, 2020 Share Posted April 17, 2020 Hello, is it possible to change the colors of the dashboard graph which represents the sales statistics? Currently we have 2 years and the color red and blue. I would like to have already 3 or 4 years instead of 2. And red for 2020, blue for 2019, and a dark gray for 2018 and a light gray for 2017 Link to comment Share on other sites More sharing options...
bsmither Posted April 17, 2020 Share Posted April 17, 2020 We can work on getting more years added after verifying the colors work. In dashboard.index.inc.php, find: $chart_data['title'] = $lang['dashboard']['title_sales_stats'].': '.$last_year.' - '.$this_year; $GLOBALS['smarty']->assign('CHART', $chart_data); On a blank line ABOVE that, add this: $chart_data['series'] = "[{color:'black'},{color:'yellow'}]"; In the skin template dashboard.index.php, find: var options = { title: '{/literal}{$CHART.title}{literal}', On a new blank line AFTER that, add this: series: {/literal}{$CHART.series}{literal}, Change the name of the colors (or #html_color_code) to correlate with the specific year. Link to comment Share on other sites More sharing options...
fabriceunko Posted April 17, 2020 Author Share Posted April 17, 2020 perfect for color. And I understood to change it .. Link to comment Share on other sites More sharing options...
bsmither Posted April 17, 2020 Share Posted April 17, 2020 I finished making the graph show more years. The changes to the code were numerous, but minor. It would be best to replace the whole section that calculates the chart data. In the admin, /sources/dashboard.index.inc.php, near line 185, find: ## Statistics (Google Charts) Then, near line 213, find: $GLOBALS['smarty']->assign('CHART', $chart_data); The following will REPLACE EVERYTHING between those two lines, including those two lines: ## Statistics (Google Charts) $no_years_to_show = 4; $chart_data['series'] = "[{color:'black'},{color:'yellow'},{color:'green'},{color:'purple'}]"; $this_year = date('Y'); $chart_data['title'] = $lang['dashboard']['title_sales_stats'].': ' . ($this_year +1 - $no_years_to_show) . ' - '.$this_year; $first_year_start = mktime(0, 0, 0, '01', '01', $this_year +1 - $no_years_to_show); $sales = $GLOBALS['db']->select('CubeCart_order_summary', array('order_date', 'total'), array('order_date' => '>='.$first_year_start, 'status' => array(2, 3), 'total' => '>0')); $data= array(); if ($sales) { ## Get data to put in chart foreach ($sales as $sale) { $year = date('Y', $sale['order_date']); $month = date('M', $sale['order_date']); if (isset($data[$year][$month])) { $data[$year][$month] += sprintf('%0.2f', $sale['total']); } else { $data[$year][$month] = sprintf('%0.2f', $sale['total']); } } } $chart_data['data'] = "['Month', "; for ($i = 0; $i < $no_years_to_show; ++$i) { $this_year_offset = $this_year - $i; $chart_data['data'] .= "'".$this_year_offset."',"; } $chart_data['data'] .= "],"; for ($month = 1; $month <= 12; $month++) { $m = date("M", mktime(0, 0, 0, $month, 10)); $chart_data['data'] .= "['$m',"; for ($i = 0; $i < $no_years_to_show; ++$i) { $year_month = (isset($data[$this_year - $i][$m]) && $data[$this_year - $i][$m]>0) ? $data[$this_year - $i][$m] : 0; $chart_data['data'] .= "$year_month,"; } $chart_data['data'] .= "],"; } $GLOBALS['smarty']->assign('CHART', $chart_data); Note the first two lines after ## Statistics (Google Charts). Here you can set the number of calendar years to include in the chart (which includes the current year). And also be able to specify what colors to use for the current year, then last year, then the year before that,, etc, etc, then the oldest year. Link to comment Share on other sites More sharing options...
fabriceunko Posted April 17, 2020 Author Share Posted April 17, 2020 Thank you very much for God's fire march. I can thus see my evolution over several years. Link to comment Share on other sites More sharing options...
bsmither Posted April 17, 2020 Share Posted April 17, 2020 FYI: https://github.com/cubecart/v6/issues/1225 Link to comment Share on other sites More sharing options...
fabriceunko Posted April 22, 2020 Author Share Posted April 22, 2020 Hello, I have another question. Is it possible to change this? IN Janvier Février Mars Avril Mai Juin Juillet Août Septembre Octobre Novembre Décembre ? Link to comment Share on other sites More sharing options...
bsmither Posted April 22, 2020 Share Posted April 22, 2020 In the admin skin template: Find: var chart = new google.visualization.LineChart(document.getElementById('chart_div')); Change to: var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); The vertical scale? That's automatic. The abbreviated names of the months? We will need to find the way for PHP to use locale-specific results in some of the instances of the date() function. Try this. In the admin /source/dashboard.index.inc.php, find: global $glob, $lang, $admin_data; Add after: setlocale(LC_TIME, "designation"); where designation is something like fr-FR for French. We need to find the very specific instances of the function date() and replace that with strftime(). There may be some tweaking involved. Be back later. Link to comment Share on other sites More sharing options...
fabriceunko Posted April 22, 2020 Author Share Posted April 22, 2020 By doing this .. I have nothing left. A white square instead of a hard graph Link to comment Share on other sites More sharing options...
bsmither Posted April 22, 2020 Share Posted April 22, 2020 In dashboard.index.inc.php: Find: $chart_data['data'] .= "['$m',"; Change to: $chart_data['data'] .= "['".setlocale(LC_TIME,"fr_FR.UTF-8", "fr_FR","fr").strftime("%B", mktime(0, 0, 0, $month, 10))."',"; I didn't get French names probably because I do not have a French library installed for PHP nor for the operating system of my web server. Revert back to LineChart and see what happens. Link to comment Share on other sites More sharing options...
fabriceunko Posted April 22, 2020 Author Share Posted April 22, 2020 So its walking but I have this fr_FR.UTF-8janvier for January and for each month I have fr_FR.UTF-8 In front of each month instead of designation I wrote fr-FR setlocale(LC_TIME, "designation"); setlocale(LC_TIME, "fr-FR"); Link to comment Share on other sites More sharing options...
bsmither Posted April 22, 2020 Share Posted April 22, 2020 Having setlocale() elsewhere, make this edit: Find: $chart_data['data'] .= "['".setlocale(LC_TIME,"fr_FR.UTF-8", "fr_FR","fr").strftime("%B", mktime(0, 0, 0, $month, 10))."',"; Change to: $chart_data['data'] .= "['".strftime("%B", mktime(0, 0, 0, $month, 10))."',"; Link to comment Share on other sites More sharing options...
fabriceunko Posted April 22, 2020 Author Share Posted April 22, 2020 This is good, I no longer have the fr_FR.UTF-8 before the names of the months However, the names of the months are in English Link to comment Share on other sites More sharing options...
bsmither Posted April 22, 2020 Share Posted April 22, 2020 Try : Replace: setlocale(LC_TIME, "fr-FR"); With: setlocale(LC_TIME, "fr_FR.UTF-8"); Link to comment Share on other sites More sharing options...
fabriceunko Posted April 22, 2020 Author Share Posted April 22, 2020 Haa perfect it works very well ... finally cube cart is almost 100% French. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.