Displaying jquery graph data according to date - php

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

Related

How to plot a graph with time on y axis and date on x axis

How to draw a line graph with time on y axis and date on x axis... . I have tried many plugins. but none of them are giving me option to put time on y axis. currently im trying to do it on http://www.chartphp.com/demo/#database/line.php but i cant find a way to put time on y axis. Both time and date are coming from my database.
i would recommend angularjs.
chart application

Time in x-axis not showing correctly for graph in flot js

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.

jpgraph x axis scale

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.

Graphing Dates with pchart

I am trying to use date values for the xaxis but cannot find any documentation on how to do so.
I found this for the old version of pchart but the function calls are not the same in the new version of pchart.
http://pchart.sourceforge.net/documentation.php?topic=advexemple20
For example my Y values are 10, 20, 30 and my X values are 2012-03-31, 2012-04-20, 2012-05-25. I cannot figure out how to add the dates using the addpoints.
I've read that you are to use the unix time stamp but then I get lost with how to format the xaxis in pcharts.

Create Chart using PHP-MySQL

I have a mysql table - request_events with three fields; request_eventsid,datetime,type.this table will track all the activities of my website day wise and also type wise.thus,type may be 1 or 2.I need to display an open-chart for understanding the progress.So I need to retrieve the ratio of type2/type1 as input day wise.How can I get all these input for last 30 days from this table.Please give me some idea....It already kill my week end.Please help me
You can get 30-day type-wise event counts with a query something like:
SELECT COUNT(type) FROM request_events
WHERE
datetime > DATE_SUB(CURDATE(),INTERVAL 30 DAY)
GROUP BY type;
You can use smart chart maker. it can help you generate any charts that is fed directly from your MySQL database, it does support a data filter option, from which you can specify the exact data you want to display in your chart, and finally it supports aggregation functions such as "count, sum, avg,..etc)
You can use smart chart maker for any types of charts. For more information please watch this video tutorial

Categories