I'm still learning some of the basics of PHP so bare with me. When making a PHPlot with tons of data from every hour for a month, the PHPlot will make a label with (Month/Day/Year Hr:Min) for each hour. This makes tons of labels if im looking at something for over a month but ok-ish for something for a few days. I've tried the TuneXAutoRange, SetXTickIncrement, and a few others and nothing seems to do anything. I need help since I'm still learning!
Your data type is implicitly 'text-data', and your data array contains 2 values per row. To PHPlot, these are 'label' and 'y', with the X being implicit. When PHPlot sees non-empty labels in the data array, it defaults to plotting those (data labels), rather than tick labels.
When your data points are uniformly spaced - and it sounds like they are - is OK to use implicit X values and put the labels into the data array. However, PHPlot will plot every single label. (You put them in the array, so it assumes you want to see them.) There is currently no way to tell PHPlot to only plot some of them, but it isn't hard to do outside of PHPlot. You just blank out N-1 of every N labels (replace with an empty string). In the PHPlot distribution, under "contrib", there is sample code called "prune_labels.php" that you can adapt and use, if you want.
There is another way to do date/time-based labels: using 'data-data' data type. Your data array rows will look like this: ('', $x, $y) with an empty label, an $x in seconds, and your Y value. You can then use tick labels to show the date/time. I am not recommending you switch to using this, as it can be more work to get the results you want. But this method better represents the data when it is sampled at irregular intervals.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I'm still learning some of the basics of PHP so bare with me. When making a PHPlot with tons of data from every hour for a month, the PHPlot will make a label with (Month/Day/Year Hr:Min) for each hour. This makes tons of labels if im looking at something for over a month but ok-ish for something for a few days. I've tried the TuneXAutoRange, SetXTickIncrement, and a few others and nothing seems to do anything. I need help since I'm still learning!
Here's my code for the PHPlot:
$graph = new PHPlot(800, 400);
for($index = 0; $index < $arrlength; $index++)
{
$data[] = array($xdata[$index], $ydata[$index]);
}
$graph->SetDataValues($data);
$graph->SetMarginsPixels(40, 40, 30, 130);
$graph->SetXDataLabelType('time');
$graph->SetXTickIncrement('14400');
$graph->SetPlotAreaWorld(NULL, 0, NULL, $maxvalue + 50);
//$graph->SetXLabelType('time', '%m/%d/%y %H:%m');
$graph->SetXLabelAngle(90);
$graph->SetLegend("Peak Value: $maxvalue KWswd Average: $average");
$graph->SetLegendPosition(0.5,1,'image',0.5,0.99);
$graph->SetDataColors('black');
$graph->SetDrawXGrid(True);
$graph->SetPlotType('lines');
$graph->DrawGraph();
Last edit: Chad Waite 2015-11-23
Here is a picture of what's happening
Your data type is implicitly 'text-data', and your data array contains 2 values per row. To PHPlot, these are 'label' and 'y', with the X being implicit. When PHPlot sees non-empty labels in the data array, it defaults to plotting those (data labels), rather than tick labels.
When your data points are uniformly spaced - and it sounds like they are - is OK to use implicit X values and put the labels into the data array. However, PHPlot will plot every single label. (You put them in the array, so it assumes you want to see them.) There is currently no way to tell PHPlot to only plot some of them, but it isn't hard to do outside of PHPlot. You just blank out N-1 of every N labels (replace with an empty string). In the PHPlot distribution, under "contrib", there is sample code called "prune_labels.php" that you can adapt and use, if you want.
There is another way to do date/time-based labels: using 'data-data' data type. Your data array rows will look like this: ('', $x, $y) with an empty label, an $x in seconds, and your Y value. You can then use tick labels to show the date/time. I am not recommending you switch to using this, as it can be more work to get the results you want. But this method better represents the data when it is sampled at irregular intervals.
Thanks, the prune_labels.php function is what I needed. Looks a lot better now!