[Help/Request] Using Chart.js to replace default charts.

Does anybody know how to replace the default charts with these ones I found on the internet called Charts.js and can be downloaded here.

If I don´t remember bad, I read a post from Nabeel that stated that the charts were hard-coded and there was no way to change them.

I’ve never done it using Charts.js, but I’ve used Morris Charts before.

  • You could probably tweak it for charts.js

What I did was put the following in

core/modules/Pilots/Pilots.php

public function morrisstatsbymonthdata()
 {

		 $data = PIREPData::getIntervalDataByMonth(array('p.pilotid'=>Auth::$userinfo->pilotid), 3);
		 header("Content-type: application/json");
		 echo json_encode($data);

 }

public function morrisstatsaircraftdata($pilotid)
 {

		 $data = StatsData::PilotAircraftFlownCountsMorris($pilotid);
		 header("Content-type: application/json");
		 echo json_encode($data);

 }

core/common/StatsData.class.php

public static function PilotAircraftFlownCountsMorris($pilotid)
{
$key = 'ac_flown_counts_1_'.$pilotid;

$counts = CodonCache::delete($key);

if($counts === true)
{
//Select aircraft types
$sql = 'SELECT a.name AS label, COUNT(p.aircraft) AS value, SUM(p.flighttime) AS hours
 FROM '.TABLE_PREFIX.'pireps p, '.TABLE_PREFIX.'aircraft a
 WHERE p.aircraft = a.id AND p.pilotid='.intval($pilotid).'
 GROUP BY a.name';

$counts = DB::get_results($sql);
CodonCache::write($key, $counts, 'medium');
}

return $counts;
}

If your using phpvms 5.5.x

core/common/StatsData.class.php

public static function PilotAircraftFlownCountsMorris($pilotid)
{
$key = 'ac_flown_counts_1_'.$pilotid;

$counts = CodonCache::delete($key);

if($counts === false)
{
//Select aircraft types
$sql = 'SELECT a.name AS label, COUNT(p.aircraft) AS value, SUM(p.flighttime) AS hours
   FROM '.TABLE_PREFIX.'pireps p, '.TABLE_PREFIX.'aircraft a
   WHERE p.aircraft = a.id AND p.pilotid='.intval($pilotid).'
   GROUP BY a.name';

$counts = DB::get_results($sql);
CodonCache::write($key, $counts, 'medium');
}

return $counts;
}

And here’s my core/templates/profile_stats.tpl/php (should really be in lib/skins/XXX/profile_stats.tpl/php)

<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js"></script>
<h3>Your Stats</h3>
<?php
/*
Added in 2.0!
*/
$chart_width = '800';
$chart_height = '250';
/* Don Not need to change anything below this here */
?>
<div align="center" style="width: 100%;">
<div id="monthdata" style="height: 250px;"></div>
</div>
<br />
<div align="center" style="width: 100%;">
<div id="aircraftdata" style="height: 250px;"></div>
</div>
<script type="text/javascript">
var json = (function () {
		 var json = null;
		 $.ajax({
				 'async': false,
				 'global': false,
				 'url': "<?php echo actionurl('/pilots/morrisstatsbymonthdata');?>",
				 'dataType': "json",
				 'success': function (data) {
						 json = data;
				 }
		 });
		 return json;
 })
 ();

new Morris.Line({
// ID of the element in which to draw the chart.
element: 'monthdata',
// Chart data records -- each entry in this array corresponds to a point on
// the chart.
data: json,
// The name of the data record attribute that contains x-values.
xkey: 'ym',
// A list of names of data record attributes that contain y-values.
ykeys: ['total'],
// Labels for the ykeys -- will be displayed when you hover over the
// chart.
labels: ['Flights']
});
</script>
<script type="text/javascript">
var json = (function () {
		 var json = null;
		 $.ajax({
				 'async': false,
				 'global': false,
				 'url': "<?php echo actionurl('/pilots/morrisstatsaircraftdata/'.Auth::$userinfo->pilotid.'');?>",
				 'dataType': "json",
				 'success': function (data) {
						 json = data;
				 }
		 });
		 return json;
 })
 ();

Morris.Donut({
element: 'aircraftdata',
data: json
});
</script>

The end result http://imgur.com/wyb2lUz

Thanks to Vangelis for providing most of the

1 Like

Thanks

just a question

it is possible to create the pirep view report ?

see exemple

Thanks

post-45474-0-43354300-1452180656.jpg

Where would you find that map? (Vataware?)

@web541

After trying that I get this error

Parse error : syntax error, unexpected ‘public’ (T_PUBLIC) in /home/techattax/public_html/airline/core/modules/Pilots/Pilots.php on line 123

What version of phpVMS are you using? And what’s line 123 for you?

What version of phpVMS are you using? And what’s line 123 for you?

I am using the latest phpVMS and line 123 has the code I copied from above.

Try copying it to the end of the file before the last }

Try copying it to the end of the file before the last }

Thank you very much got it working now!

np Glad to help

yes in vateware

Correct me if I’m wrong, but I don’t think phpVMS stores all that information in the database. So I don’t think that map is possible.

you are right ,but I have Flight Position Tracker

As I do not own that module, I can’t help you, however if it records the positions in your database then it is probably possible in some way, shape or form.

if you want I can send by mail

Hey all,

For some reason, I couldn’t get the PIREP chart to show.  The aircraft one works perfectly, but not the PIREP line graph. Going to /action.php/pilots/morrisstatsbymonthdata does not show populated JSON data either.

I am on phpvms 5.5.2 on php5.6

Edit: Ignore.  It was because I was running it on a local copy of my site and the database is older than a month, hence no data for the last month! Duh…

Sorry to open an old topic, but is it also possible to show this on the public profile?

It is showing but on all the pilots the same numbers

8 hours ago, ncd200 said:

Sorry to open an old topic, but is it also possible to show this on the public profile?

It is showing but on all the pilots the same numbers

Which graph are you looking to get? For the donut, you would have to change this

'url': "\<?php echo actionurl('/pilots/morrisstatsaircraftdata/'.Auth::$userinfo-\>pilotid.'');?\>",

to this

'url': "\<?php echo actionurl('/pilots/morrisstatsaircraftdata/'.$pilot-\>pilotid.'');?\>",

 

And similarly, for the monthly chart, you would have to replace this

public function morrisstatsbymonthdata() { $data = PIREPData::getIntervalDataByMonth(array('p.pilotid'=\>Auth::$userinfo-\>pilotid), 3); header("Content-type: application/json"); echo json\_encode($data); }

with this

public function morrisstatsbymonthdata($pilotid) { $data = PIREPData::getIntervalDataByMonth(array('p.pilotid'=\> DB::escape($pilotid)), 3); header("Content-type: application/json"); echo json\_encode($data); }

And this

$.ajax({ 'async': false, 'global': false, 'url': "\<?php echo actionurl('/pilots/morrisstatsbymonthdata');?\>", 'dataType': "json", 'success': function(data) { json = data; } }); return json;

Replace with this

$.ajax({ 'async': false, 'global': false, 'url': "\<?php echo actionurl('/pilots/morrisstatsbymonthdata/'.$pilot-\>pilotid.'');?\>", 'dataType': "json", 'success': function(data) { json = data; } }); return json;

and I would think that would work.

thanks, will try this when our new domain is set up

much appreciated!