how can i tell jpgraph to show x-axis ticks every month? I have two charts, in one i show results from 1 year and on other i show results from beginning to end. On year graph it shows weekly results and i like it but in case of showing bigger date range (in my case from 1.4.2010. till 10.1.2013. it show tick only every one year so i have tick on 1.4.2010, 1.4.2011, ...
Important part of the code where i define x-axis properties:
$graph->xaxis->SetTickLabels($timestamp);
$graph->xaxis->scale->SetDateAlign(MONTHADJ_1);
$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
$graph->xaxis->SetLabelAngle(-45);
$graph->xaxis->SetLabelMargin(2);
$graph->xaxis->SetLabelAlign('left','top');
$graph->xaxis->SetLabelFormatString('d.m.Y',true);
$graph->xaxis->HideFirstLastLabel();
Timestamp array is unix timestamp values converted from mysql dates,and timestamps are correct. I checked them. Also results in the graphs are fine, only i want more ticks on x axis.
To answer my own question,and close it, here is what i added (combined with old xaxis properties):
require_once ('jpgraph/jpgraph_utils.inc.php');
$dateUtils = new DateScaleUtils();
list($tickPos,$minTickPos) = $dateUtils->getTicks($timestamp,DSUTILS_MONTH1);
$graph->xaxis->SetTickPositions($tickPos,$minTickPos);
$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
$graph->xaxis->SetLabelAngle(-45);
$graph->xaxis->SetLabelMargin(2);
$graph->xaxis->SetLabelAlign('left','top');
$graph->xaxis->SetLabelFormatString('d.m.Y',true);
$graph->xaxis->HideFirstLastLabel();
Also i changed scale of graph to intlin, it was datlin before.
Related
I'm plotting graph using flot js. Now date stored in the database is in this form.
2015-10-29 11:35:33
I convert it to miliseconds, pass to ajax to plot the graph and that graph ought to display date in x-axis not in miliseconds but in readable date.
This is how its shown presently,
If you notice the x-axis, I believe its only showing the time as value for y are all for the same day, same hour but slightly difference in minutes.Please take a look at below table that shows the value (total_bv) and dates (as_of_date).
Problem is, date the date shown in x-axis. what does that 03:3, 03:38 and so forth about. I think its the time which doesn't converted to correct time zone?
Because in the PHP script where I get the data from database, I use timezone asia/kuala lumpur. If I don't use this timezone the time displayed in x-axis starts with 10:36, 10:38 and so forth.. SO can anyone tell me first how to show the correct Date & time in x-axis in readable format?
date_default_timezone_set("Asia/Kuala_Lumpur");
$acceptedUser = new search();
$sales = $acceptedUser->get_sales_graph();
$before = array();
foreach($sales as $k=>$v)
{
$date = strtotime($v['as_of_date']) * 1000;
array_push($before, array("datey" => $date, "bv" => $v['total_bv']));
}
echo json_encode($before);
So it seems you have two issues:
The conversion of date/time strings from your database to JavaScript millisecond timestamps, paying attention to time zones.
Displaying some kind of date/time string for your tick values.
Both of these are addressed by the flot.js documentation.
First of all, flot assumes that timestamps are UTC. If you want to change that, you can do so through setting the axis' timezone property to browser (converts timestamps according to the user's browser), or you can use timezone.js. However most devs just pretend that the timestamp they are using is already in the correct timezone anyway (which is essentially what you're doing and have noticed).
Second, use an explicit format string for the timeformat property with the axis ticks. The documentation has the full list of replaceable format specifiers.
I am using jQuery flot for plotting graphs in my PHP page. My page retrieves data from PostgreSQL database and plot the values on the graph having date on x axis and cost on y axis.
Problem Statement: I have data according to julian date in my db but it may not be starting from 1st day of the month. Now my plot shows data for 30 days of the month and I want to plot the values retrieved from db on correct coordinate and not from starting of the x axis coordinate 0. The days previous to the one retieved from db should show 0 or no values.
Requirement: Any logic for displaying this data dynamically on correct coordinate as the plot function exposed by jQuery flot requires manual mapping of coordinates and values.
I'm not sure if I understand your question, does this help?
j$.plot(j$("#placeholder"),[d1],{
xaxis:
{ mode: "time",
min: <?php echo $start_data;?>,
max: 30
}
}
I am trying to work with the Google analytics API. I use following code to request data:
$ga = new gapi($ga_email,$ga_password);
$ga->requestReportData($ga_profile_id,'date',array('pageviews', 'visits'), 'date', "",$start,$end,1,1000);
$results = $ga->getResults();
Which can then be iteratd with a loop for each date
After googling I can't seem to find the answer or it is possible to get the total visits, pageviews, newvisits, uniquevisits,percentnewvisits.... for a certain timespan?
If you request for example.
Dimesnion: Date
Metrics: Pageviews,visits, UniqueVists
StartDate: 20130101
endDate: 20130201
You will have a row for each date between Startdate and endDate with the values summed up for that
date.
If what you want is them summed up for all the dates then You could try a dimension like Visitor type then you will only end up with 2 rows new visits and returning visits. Summed up for the time between startdate and end date.
Unfortuantly you have to select at least one dimension so you cant just get the Metrics. Using Visitor type should work then you only have to sum up the two rows that come back. Another idea would be if your start date and end date have the same Year then you could use ga:year as your dimension. Then you will only have one row summed up with all your metrics.
Edit: found something else.
You could also try looking at totalsForAllResults it appears to be returned in the V3 of the core reporting client library.
I'm new to MySQL and PHP but was wondering if someone could help me with a little project I'm doing for my boss.
I have a SQL database (MyDB) and a table in there (mytable) with two columns - the first column (index) is an auto-incrementing integer from 1-10, the second column (date) has different dates and timestamps in the format of Year-month-day time 2013-04-12 1326
I'm trying to create a simple PHP page that first gets the current date (easy enough) then looks at the table and shows the number of rows that fall within yesterday's date. For example, if I have 3 rows with 2013-04-11 XXXX and 2 rows with 2013-04-12 XXXX (and today is the 12th April 2013) the page will display 3. (The time is not important but we can't remove it from the table as it's auto created by one of the other staff's programs and he refuses to change it).
So far I've got my php page, done a connection to the DB and defined two variables:
$startdate = date('Y'."-".'n'."-".'d'." "."0000");
$enddate = date('Y'."-".'n'."-".'d'." "."2359");
As the timestamp doesn't matter I've gone for the min/max possible on the variables. I realise this will only give the current date, trying to work out how to get it to display the previous day as the date in the variable.
Now I'm trying to create a sql query that will count the number of rows where the date field falls within the startdate and enddate variables (-1 day) but not too sure where to start or how this would look. I then need to output this as a variable in PHP so I can echo it later in the page.
Anyone able to point me in the right direction? Hope any of this makes sense.
You could write a query with no params to do this (if its always just yesterday).
SELECT * FROM <table>
WHERE DATE_FORMAT(<date column>,'%j-%Y') = DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 DAY), '%j-%Y');
Date functions in the where clause might not be super awesome performance wise
I have a mysql table with four colums:
date, time, ip, user
When loading the results I get something like this:
03-21 17:10:33 123.456.789.101 TestUser
03-21 17:12:31 123.456.789.101 TestUser
03-25 17:16:33 123.456.789.101 TestUser
I want to highlight (give a diff. text color) the rows with the same date AND time if within a 2min range, like the first two rows in my example.
How to do that?
I would recommend dropping the date column in you database, and changing the TIME to a full TIMESTAMP, then using the MySQL timediff function to determine the difference between the two.
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_timediff
Once you have determined the time difference between the two, as you are echoing out the results add some inline css style or a different class to change the text color or background colour based on that difference.
Without seeing your code, I can do little to help though.
You could use de strtotime function in PHP that converts a string into a date. Using some css styling is posible to highlight the results. For example:
$t1 = strtotime('03-21 17:10:33');
$t2 = strtotime ('03-21 17:12:31');
if( abs($t1-$t2) <= 120|| ){ //120 is the number of secons in 2 minutes
}