ahughes3 Posted November 21, 2015 Report Share Posted November 21, 2015 Hi all, I am skinning a new admin skin and I would like to change the look of the initial dashboard chart showing last 30 day's pireps. I can see that the chart is a swf object compiled from data and processed into the chart. My question is, does anyone know how to extract the same data in a raw format so I can use it in a custom chart script? I want to take the raw data myself using php and then pass it to the chart script that I'm using in order to then populate it. Grateful to anyone who can point me in the right direction to either a php script that would extract the data, or where I can find a dataclass that will give me the data. Thanks Quote Link to comment Share on other sites More sharing options...
web541 Posted November 21, 2015 Report Share Posted November 21, 2015 Try admin/modules/Dashboard/Dashboard.php on line 44. This leads to the OFCharts.class.php in core/common Quote Link to comment Share on other sites More sharing options...
ahughes3 Posted November 21, 2015 Author Report Share Posted November 21, 2015 Thanks web541, I have looked at both of those files. The OFCharts.class.php looks to just contain code that process the raw data from a data variable or dump somewhere so I don't think it extracts data itself. The dashboard.php does have something in it which looks like it might be the right sort of thing. {"data-file":"<?php echo adminaction('/dashboard/pirepcounts');?>"}); The above code looks like it's creating a data file with the contents of the "pirepcounts" but I can't tell where this data file is, or if it contains raw data. Or in fact whether I'm barking up totally the wrong tree lol. If I understood php coding better, or the phpvms structure, I'd probably be able to do it quicker and easier. I'll keep plodding on though, don't like being beaten . Quote Link to comment Share on other sites More sharing options...
web541 Posted November 21, 2015 Report Share Posted November 21, 2015 <?php echo adminaction('/dashboard/pirepcounts');?> This line basically means go the the admin section of the website and go to your Dashboard ->Dashboard.php (so admin/modules/Dashboard/Dashboard.php) In this file, you'll see a function called public function pirepcounts() { and that function is basically triggered by that link above through the action.php, so it'd be www.yourva.com/admin/action.php/dashboard/pirepcounts That might lead you to some code (JSON Perhaps) You might be able to make a new function with this https://github.com/gfazioli/morris-php Quote Link to comment Share on other sites More sharing options...
Members Vangelis Posted November 22, 2015 Members Report Share Posted November 22, 2015 web541 is right the data is being converted to json format with public function pirepcounts() { function if you run it with http://www.yoursite.com/admin/action.php/dashboard/pirepcounts You will get this result { "elements": [ { "type": "line", "values": [ 1 ], "dot-style": { "type": "solid-dot", "dot-size": 3, "halo-size": 1, "colour": "#3D5C56" }, "width": 2, "text": "", "font-size": 10, "colour": "#3D5C56" } ], "title": { "text": "Past 30 days PIREPS" }, "y_axis": { "min": -1, "max": 2, "steps": 1 }, "x_axis": { "labels": { "labels": [ "2015-11-04" ], "rotate": 270 } }, "bg_colour": "#FFFFFF" } But this is for ofCharts if you are using another charting code you might need to adjust it or make a new function Quote Link to comment Share on other sites More sharing options...
ahughes3 Posted November 23, 2015 Author Report Share Posted November 23, 2015 Right, I think I get what you are saying. Sincerest thanks to both of you, but I suspect I'm not done with you yet! So the chart I want to create is using Morris Charts (morris.js) and the script for creating the chart using static data is below. This is just where you would physically enter the values if the chart is unlikely to change often. new Morris.Line({ // ID of the element in which to draw the chart. element: 'myfirstchart', // Chart data records -- each entry in this array corresponds to a point on // the chart. data: [ { year: '2008', value: 20 }, { year: '2009', value: 10 }, { year: '2010', value: 5 }, { year: '2011', value: 5 }, { year: '2012', value: 20 } ], // The name of the data record attribute that contains x-values. xkey: 'year', // A list of names of data record attributes that contain y-values. ykeys: ['value'], // Labels for the ykeys -- will be displayed when you hover over the // chart. labels: ['Value'] }); In my case I want it to show the "past 30 day pireps" as per the chart on the frontpage of the dashboard. I think the "function" that compiles the data produces the right content for my needs, I just don't know how to utilise the "function" for my needs or whether I need to work out a modified one. Would it be as simple as adding the "variables" to the script as follows: new Morris.Line({ // ID of the element in which to draw the chart. element: 'myfirstchart', // Chart data records -- each entry in this array corresponds to a point on // the chart. data: [ { year: '$bar_titles', value: $bar_values } ], // The name of the data record attribute that contains x-values. xkey: 'Date', // A list of names of data record attributes that contain y-values. ykeys: ['# of Pireps'], // Labels for the ykeys -- will be displayed when you hover over the // chart. labels: ['Pireps'] }); I suspect this won't work because the above won't know how to handle translating the variable output into multiple lines as in the first example. Any pointers? I will attempt to test it, but I'm sure it will not work. Quote Link to comment Share on other sites More sharing options...
Members Vangelis Posted November 23, 2015 Members Report Share Posted November 23, 2015 Have a look at this https://jsfiddle.net/vangelisb/a2hvgbo3/ With an ajax request you will be able to get the data you want Quote Link to comment Share on other sites More sharing options...
ahughes3 Posted November 24, 2015 Author Report Share Posted November 24, 2015 Thanks Vangelis and I think I get it, but to achieve what you are suggesting I would presumably need to extract data from the database using php, then convert it to json format for use with morris charts yes? I mean in order to create; var Flightsdata = [{Date:"2014-02-05",Flights:810}, {Date:"2014-02-09",Flights:2}, {Date:"2014-02-10",Flights:6}, {Date:"2014-02-10",Flights:210}, {Date:"2014-02-12",Flights:9}, {Date:"2014-02-13",Flights: 543}]; that would require me to create a php script to query the database and then turn it into the json format. Or is there a function in phpvms which already calls this data? Quote Link to comment Share on other sites More sharing options...
ahughes3 Posted November 24, 2015 Author Report Share Posted November 24, 2015 I have pulled together this script from the net. It is essentially just a script that will fetch the table row content of the phpvms_pireps table and display it in a web browser in json format. It's just so I can test out how it works and looks. The only problem is, the resulting page is blank apart from the message "connected successfully" which is obviously my check that db connection is established. Can you spot anything I'm doing wrong? Or am I again making a whole lot of unnecessary work for myself. <?php //open connection to mysql db $connection = mysqli_connect("localhost","********","********","********") or die("Error " . mysqli_error($connection)); //Check the connection worked if (!$connection) { die("Connection failed: " . mysqli_connect_error()); } else { echo "Connected successfully"; } //fetch table rows from mysql db $sql = "SELECT * FROM phpvms_pireps"; $result = mysqli_query($connection, $sql) or die("Error in Selecting " . mysqli_error($connection)); //create an array $emparray = array(); while($row =mysqli_fetch_assoc($result)) { $emparray[] = $row; } echo json_encode($emparray); //close the db connection mysqli_close($connection); ?> Quote Link to comment Share on other sites More sharing options...
Members Vangelis Posted November 24, 2015 Members Report Share Posted November 24, 2015 all this code could be replaced with $allPireps=PIREPData::findPIREPS($params=""); echo json_encode($allPireps); But this makes all the pireps in 1 json string and if you have to many pireps you will get Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 29413988 bytes) in like i did Quote Link to comment Share on other sites More sharing options...
ahughes3 Posted November 24, 2015 Author Report Share Posted November 24, 2015 all this code could be replaced with $allPireps=PIREPData::findPIREPS($params=""); echo json_encode($allPireps); You mean replace my php script for the above? That won't work without the calls to the database will it? Plus, this will return all pirep data whereas I just want the last 30 days as per the main dashboard chart. Quote Link to comment Share on other sites More sharing options...
Members Vangelis Posted November 24, 2015 Members Report Share Posted November 24, 2015 add this function in core/common/Dashboard.php public function getpireps() { $data = PIREPData::getIntervalDataByDays(array(), 30); header("Content-type: application/json"); echo json_encode($data); } in admin/templates.tpl at the end add this code <script type="text/javascript"> var json = (function () { var json = null; $.ajax({ 'async': false, 'global': false, 'url': "<?php echo adminaction('/dashboard/getpireps');?>", 'dataType': "json", 'success': function (data) { json = data; } }); return json; }) (); new Morris.Line({ // ID of the element in which to draw the chart. element: 'myfirstchart', // 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> and now where ever in the template you want to call the morris chart add <div id="myfirstchart" style="height: 250px;"></div> Quote Link to comment Share on other sites More sharing options...
ahughes3 Posted November 24, 2015 Author Report Share Posted November 24, 2015 As always Vangelis, your support is much appreciated. The first lot of code throws up a syntax error for me, but I have compared it to other functions and it looks ok. Any ideas as to why it might be causing an error? If I upload it, it does actually throw up a parsing error. Quote Link to comment Share on other sites More sharing options...
Members Vangelis Posted November 24, 2015 Members Report Share Posted November 24, 2015 No idea when I get home I will have look but on my site it is working if you want you can login using the demo passwords www. Baggelis.com/phpvms Quote Link to comment Share on other sites More sharing options...
ahughes3 Posted November 24, 2015 Author Report Share Posted November 24, 2015 No idea when I get home I will have look but on my site it is working if you want you can login using the demo passwords www. Baggelis.com/phpvms Ignore me, I'm an idiot and was putting it into the wrong dashboard. Just tried it now and it works perfectly, I'm just annoyed at myself for not being able to work it out on my own . Still it's always a step further along the learning path . Thanks again Vangelis and Web541. 1 Quote Link to comment Share on other sites More sharing options...
RuiMiguel Posted September 17, 2016 Report Share Posted September 17, 2016 (edited) Hi Vangelis, I'm trying to change the chart public profile,but it does not work you can help me? my code core/pilots public function morrisstatsdaysdata() { $data = PIREPData::getIntervalDataByDays(array('p.pilotid'=>$pilotid), 30); header("Content-type: application/json"); echo json_encode($data); } public profile <?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="daysdata" style="height: 175px;"></div> </div> <script type="text/javascript"> var json = (function () { var json = null; $.ajax({ 'async': false, 'global': false, 'url': "<?php echo actionurl('/pilots/morrisstatsdaysdata');?>", 'dataType': "json", 'success': function (data) { json = data; } }); return json; }) (); new Morris.Line({ // ID of the element in which to draw the chart. element: 'daysdata', // 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: ['Voos'] }); </script> thank you Rui Miguel Edited September 17, 2016 by RuiMiguel Quote Link to comment Share on other sites More sharing options...
Members Vangelis Posted September 17, 2016 Members Report Share Posted September 17, 2016 if i understand well you want to change index.php/profile/stats with a morris chart ? Quote Link to comment Share on other sites More sharing options...
RuiMiguel Posted September 17, 2016 Report Share Posted September 17, 2016 yes in public_profile Quote Link to comment Share on other sites More sharing options...
web541 Posted September 17, 2016 Report Share Posted September 17, 2016 (edited) If you also want the http://www.vawebsite...p/profile/stats page with morris charts (as suggested above) then check this out http://forum.phpvms....ts/#entry122438 But I see you were referring to the public profile page. EDIT: Just saw that you posted on that thread a while back so you probably already know about it. Here is the public profile chart template = pilots_public_profile.php Add the following, make sure "morris charts" has been referenced on your page somewhere (layout.php?) <div id="pirepchart" style="height: 250px;"></div> <script type="text/javascript"> var json = (function () { var json = null; $.ajax({ 'async': false, 'global': false, 'url': "<?php echo actionurl('/profile/pirepchart');?>", 'dataType': "json", 'success': function (data) { json = data; } }); return json; }) (); new Morris.Line({ // ID of the element in which to draw the chart. element: 'pirepchart', // 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> core/modules/Profile/Profile.php public function pirepchart() { $pilotid = Auth::$userinfo->pilotid; $data = PIREPData::getIntervalDataByDays(array('p.pilotid' => $pilotid), 30); header("Content-type: application/json"); echo json_encode($data); } Edited September 17, 2016 by web541 Quote Link to comment Share on other sites More sharing options...
RuiMiguel Posted September 19, 2016 Report Share Posted September 19, 2016 hi web541 It works but does not appear the last 30 days or the date see the picture thanks Rui Miguel Quote Link to comment Share on other sites More sharing options...
web541 Posted September 19, 2016 Report Share Posted September 19, 2016 Weird, where did you put this? pilot_public_profile.php? It's working for me. Quote Link to comment Share on other sites More sharing options...
RuiMiguel Posted September 19, 2016 Report Share Posted September 19, 2016 (edited) yes pilot_public_profile.php Edited September 20, 2016 by RuiMiguel Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.