Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 11/26/19 in all areas

  1. 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 base code.
    1 point
×
×
  • Create New...