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

**URL:** <https://forum.phpvms.net/t/help-request-using-chart-js-to-replace-default-charts/10735>\
**Category:** Development Help\
**Created:** [January 6, 2016, 9:40pm UTC](https://forum.phpvms.net/t/help-request-using-chart-js-to-replace-default-charts/10735 "2016-01-06T21:40:18Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![TechAttax](https://forum.phpvms.net/letter_avatar_proxy/v4/letter/t/e68b1a/32.png) [@TechAttax](https://forum.phpvms.net/u/TechAttax)\
**Post date:** [January 6, 2016, 9:40pm UTC](https://forum.phpvms.net/t/help-request-using-chart-js-to-replace-default-charts/10735/1 "2016-01-06T21:40:18Z")

</div>

Does anybody know how to replace the default [charts](http://puu.sh/mm5Yt/2ead84e794.png) with these ones I found on the internet called [Charts.js](http://www.chartjs.org/) and can be downloaded [here](http://www.chartjs.org/).

---

<div class="post-metadata">

**Author:** ![ctabuyo](https://forum.phpvms.net/user_avatar/forum.phpvms.net/ctabuyo/32/767_2.png) [@ctabuyo](https://forum.phpvms.net/u/ctabuyo)\
**Post date:** [January 6, 2016, 10:15pm UTC](https://forum.phpvms.net/t/help-request-using-chart-js-to-replace-default-charts/10735/2 "2016-01-06T22:15:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![web541](https://forum.phpvms.net/letter_avatar_proxy/v4/letter/w/59ef9b/32.png) [@web541](https://forum.phpvms.net/u/web541)\
**Post date:** [January 7, 2016, 1:47am UTC](https://forum.phpvms.net/t/help-request-using-chart-js-to-replace-default-charts/10735/3 "2016-01-07T01:47:25Z")

</div>

I’ve never done it using Charts.js, but I’ve used [Morris Charts](http://morrisjs.github.io/morris.js/) 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](http://imgur.com/wyb2lUz)

Thanks to Vangelis for providing most of the

---

<div class="post-metadata">

**Author:** ![RuiMiguel](https://forum.phpvms.net/letter_avatar_proxy/v4/letter/r/ba9def/32.png) [@RuiMiguel](https://forum.phpvms.net/u/RuiMiguel)\
**Post date:** [January 7, 2016, 3:31pm UTC](https://forum.phpvms.net/t/help-request-using-chart-js-to-replace-default-charts/10735/4 "2016-01-07T15:31:44Z")

</div>

Thanks

just a question

it is possible to create the pirep view report ?

see exemple

Thanks

![post-45474-0-43354300-1452180656.jpg](https://phpvms-forum.nyc3.digitaloceanspaces.com/original/2X/4/4652e595d53c69387722d5bef3d3c8d4cda07844.jpeg)

---

<div class="post-metadata">

**Author:** ![web541](https://forum.phpvms.net/letter_avatar_proxy/v4/letter/w/59ef9b/32.png) [@web541](https://forum.phpvms.net/u/web541)\
**Post date:** [January 7, 2016, 8:00pm UTC](https://forum.phpvms.net/t/help-request-using-chart-js-to-replace-default-charts/10735/5 "2016-01-07T20:00:21Z")

</div>

Where would you find that map? (Vataware?)

---

<div class="post-metadata">

**Author:** ![TechAttax](https://forum.phpvms.net/letter_avatar_proxy/v4/letter/t/e68b1a/32.png) [@TechAttax](https://forum.phpvms.net/u/TechAttax)\
**Post date:** [January 7, 2016, 8:23pm UTC](https://forum.phpvms.net/t/help-request-using-chart-js-to-replace-default-charts/10735/6 "2016-01-07T20:23:11Z")

</div>

@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**

---

<div class="post-metadata">

**Author:** ![web541](https://forum.phpvms.net/letter_avatar_proxy/v4/letter/w/59ef9b/32.png) [@web541](https://forum.phpvms.net/u/web541)\
**Post date:** [January 7, 2016, 8:27pm UTC](https://forum.phpvms.net/t/help-request-using-chart-js-to-replace-default-charts/10735/7 "2016-01-07T20:27:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TechAttax](https://forum.phpvms.net/letter_avatar_proxy/v4/letter/t/e68b1a/32.png) [@TechAttax](https://forum.phpvms.net/u/TechAttax)\
**Post date:** [January 7, 2016, 8:49pm UTC](https://forum.phpvms.net/t/help-request-using-chart-js-to-replace-default-charts/10735/8 "2016-01-07T20:49:51Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![web541](https://forum.phpvms.net/letter_avatar_proxy/v4/letter/w/59ef9b/32.png) [@web541](https://forum.phpvms.net/u/web541)\
**Post date:** [January 7, 2016, 8:56pm UTC](https://forum.phpvms.net/t/help-request-using-chart-js-to-replace-default-charts/10735/9 "2016-01-07T20:56:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TechAttax](https://forum.phpvms.net/letter_avatar_proxy/v4/letter/t/e68b1a/32.png) [@TechAttax](https://forum.phpvms.net/u/TechAttax)\
**Post date:** [January 7, 2016, 8:59pm UTC](https://forum.phpvms.net/t/help-request-using-chart-js-to-replace-default-charts/10735/10 "2016-01-07T20:59:54Z")

</div>

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

Thank you very much got it working now!

---

<div class="post-metadata">

**Author:** ![web541](https://forum.phpvms.net/letter_avatar_proxy/v4/letter/w/59ef9b/32.png) [@web541](https://forum.phpvms.net/u/web541)\
**Post date:** [January 7, 2016, 9:00pm UTC](https://forum.phpvms.net/t/help-request-using-chart-js-to-replace-default-charts/10735/11 "2016-01-07T21:00:52Z")

</div>

np Glad to help

---

<div class="post-metadata">

**Author:** ![RuiMiguel](https://forum.phpvms.net/letter_avatar_proxy/v4/letter/r/ba9def/32.png) [@RuiMiguel](https://forum.phpvms.net/u/RuiMiguel)\
**Post date:** [January 8, 2016, 10:02am UTC](https://forum.phpvms.net/t/help-request-using-chart-js-to-replace-default-charts/10735/12 "2016-01-08T10:02:41Z")

</div>

yes in vateware

---

<div class="post-metadata">

**Author:** ![web541](https://forum.phpvms.net/letter_avatar_proxy/v4/letter/w/59ef9b/32.png) [@web541](https://forum.phpvms.net/u/web541)\
**Post date:** [January 8, 2016, 7:57pm UTC](https://forum.phpvms.net/t/help-request-using-chart-js-to-replace-default-charts/10735/13 "2016-01-08T19:57:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![RuiMiguel](https://forum.phpvms.net/letter_avatar_proxy/v4/letter/r/ba9def/32.png) [@RuiMiguel](https://forum.phpvms.net/u/RuiMiguel)\
**Post date:** [January 8, 2016, 9:26pm UTC](https://forum.phpvms.net/t/help-request-using-chart-js-to-replace-default-charts/10735/14 "2016-01-08T21:26:50Z")

</div>

you are right ,but I have Flight Position Tracker

---

<div class="post-metadata">

**Author:** ![web541](https://forum.phpvms.net/letter_avatar_proxy/v4/letter/w/59ef9b/32.png) [@web541](https://forum.phpvms.net/u/web541)\
**Post date:** [January 8, 2016, 9:31pm UTC](https://forum.phpvms.net/t/help-request-using-chart-js-to-replace-default-charts/10735/15 "2016-01-08T21:31:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![RuiMiguel](https://forum.phpvms.net/letter_avatar_proxy/v4/letter/r/ba9def/32.png) [@RuiMiguel](https://forum.phpvms.net/u/RuiMiguel)\
**Post date:** [January 8, 2016, 10:40pm UTC](https://forum.phpvms.net/t/help-request-using-chart-js-to-replace-default-charts/10735/16 "2016-01-08T22:40:28Z")

</div>

if you want I can send by mail

---

<div class="post-metadata">

**Author:** ![shakamonkey88](https://forum.phpvms.net/user_avatar/forum.phpvms.net/shakamonkey88/32/969_2.png) [@shakamonkey88](https://forum.phpvms.net/u/shakamonkey88)\
**Post date:** [February 13, 2018, 2:20pm UTC](https://forum.phpvms.net/t/help-request-using-chart-js-to-replace-default-charts/10735/17 "2018-02-13T14:20:49Z")

</div>

Hey all,

For some reason, I couldn’t get the PIREP chart to show.&nbsp; 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.&nbsp; 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…

---

<div class="post-metadata">

**Author:** ![ncd200](https://forum.phpvms.net/user_avatar/forum.phpvms.net/ncd200/32/3024_2.png) [@ncd200](https://forum.phpvms.net/u/ncd200)\
**Post date:** [January 9, 2020, 1:21pm UTC](https://forum.phpvms.net/t/help-request-using-chart-js-to-replace-default-charts/10735/18 "2020-01-09T13:21:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![web541](https://forum.phpvms.net/letter_avatar_proxy/v4/letter/w/59ef9b/32.png) [@web541](https://forum.phpvms.net/u/web541)\
**Post date:** [January 9, 2020, 10:24pm UTC](https://forum.phpvms.net/t/help-request-using-chart-js-to-replace-default-charts/10735/19 "2020-01-09T22:24:47Z")

</div>

> 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.'');?\>",

```

&nbsp;

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.

---

<div class="post-metadata">

**Author:** ![ncd200](https://forum.phpvms.net/user_avatar/forum.phpvms.net/ncd200/32/3024_2.png) [@ncd200](https://forum.phpvms.net/u/ncd200)\
**Post date:** [January 13, 2020, 7:47am UTC](https://forum.phpvms.net/t/help-request-using-chart-js-to-replace-default-charts/10735/20 "2020-01-13T07:47:24Z")

</div>

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

much appreciated!
