I'm generating a graph with JPGraph and it ends before it should, with a gap (it does not remove data, though). Not only that, it also adds some weird numbers, they look like hours and minutes, but some are different than my hour format which is HH:ii, so I don't know what they are. These numbers are not stable and change depending by how much dates the xaxis has (I guess).
In fact, there is no issue with a tenth of the data used for the previous chart:
I've already checked everything regarding the data I pass to the functions, both the dates and the actual data have the same count().
This issue only arises when using the scale $graph->SetScale("datlin"), in fact if I use textlin this does not happen, but the tick count is not automatic, like with the datlin scale.
I don't know if it's a bug in the library or if I'm doing something wrong.
Here is the code for the graph generation:
$graph = new Graph\Graph(1100, 600);
$graph->SetMargin(100, 100, 100, 100);
$graph->SetScale("datlin");
if (count($dates) != 0)
$graph->xaxis->SetTextTickInterval(count($dates) / (count($dates) / 10)); //Is this even needed, since I have the datlin? Removing it does not fix my problem nor does it change anything.
$graph->xaxis->SetTickLabels($dates);
$graph->xaxis->SetLabelAngle(90);
$graph->xaxis->SetFont(FF_ARIAL, FS_NORMAL, 8);
$graph->xaxis->SetTitle('Tempo [gg-MM-aaaa hh:mm]', 'center');
$graph->xaxis->SetTitleSide(SIDE_BOTTOM);
$graph->xaxis->SetPos('min');
$graph->xaxis->title->SetMargin(100);
$graph->xaxis->title->SetFont(FF_ARIAL, FS_BOLD, 10);
//This is the ugly solution, but it only removes the label with the weird numbers, not the gap created at the end.
$graph->xaxis->HideFirstTickLabel(false);
$graph->xaxis->HideLastTickLabel(false);
$graph->xgrid->Show();
$sensorDataWithoutFirst = array_slice($data, 1, null, true);
$index = 0;
foreach ($yAxisTypes as $_ => $type) {
... creating y axis ...
}
//Converti i valori in una matrice di double, rimuove anche le chiavi
$firstSensorValues = array_values(array_map(function ($value) {
if (is_bool($value))
return false;
return (double) $value;
}, $data[$sezioneSensorList[0]->id]));
$p1 = new Plot\LinePlot($firstSensorValues);
$p1->SetColor($colors[0]);
$p1->SetLegend($sezioneSensorList[0]->Nome);
$graph->yaxis->title->SetFont(FF_ARIAL, FS_BOLD, 10);
//Spostalo dove può essere visto
$graph->yaxis->title->SetMargin(40);
$graph->yaxis->title->Set($sezioneSensorList[0]->tipoSensore->nome . " [" . $sezioneSensorList[0]->tipoSensore->UnitaMisura . "]");
$graph->Add($p1);
$yAxisTypes = array_slice($yAxisTypes, 1);
$colorIndex = 1;
//The remaining code is for creating plots, probably not related to my issue, but I kept it anyway:
foreach ($sensorDataWithoutFirst as $id => $values) {
//Obtain the sensor based on its id within the sectionSensorList (it is an array not a collection)
$sensoreCorrente = $sezioneSensorList[array_search($id, array_column($sezioneSensorList, 'id'))];
//Convert values into an array of doubles
$values = array_map(function ($value) {
if (is_bool($value))
return false;
return (double) $value;
}, array_values($values));
$plot = new Plot\LinePlot($values);
$plot->SetColor($colors[$colorIndex]);
$plot->SetLegend($sensoreCorrente->Nome);
//Instead of adding the graph to the y-axis by index, add it to the y-axis containing the sensor type
//If the sensor type is the same as the first one (the one that uses the default y-axis and not the yn-axis array), draw the graph on the default y-axis
if ($sensoreCorrente->tipoSensore->nome == $sezioneSensorList[0]->tipoSensore->nome) {
$graph->Add($plot);
}
foreach ($yAxisTypes as $typeIndex => $type) {
//if the sensor type is the same as the current y-axis, draw the graph on that y-axis
if ($type->nome == $sensoreCorrente->tipoSensore->nome) {
$graph->AddY($typeIndex, $plot);
}
}
$colorIndex = ($colorIndex + 1) % count($colors);
}
$graph->legend->Pos(0.5, 0.05, 'center', 'top');
$graph->Stroke($chartImagePath);
... other code not influencing this ...