This class is designed to help you managing the data used to create the charts. You'll find bellow a short summary
of all the embeded function and their related parameters. Functions categories :
pData
void pData()
This function create a new pData object. This object will be used during all the steps of the data population. Data will
be extracted from this object using GetData() and GetDataDescription().
// This will create a new pData object
$DataSet = new pData();
ImportFromCSV
void ImportFromCSV($FileName,$Delimiter=",",$DataColumns=-1,$HasHeader=FALSE,$DataName=-1)
This function is used to import CSV files (local or remote). Many arguments can be used. The default column delimiter
is the comma character.
// This will import the file http://my.domain.com/myData.csv using each column as a serie
$DataSet->ImportFromCSV("http://my.domain.com/myData.csv");
// This will import the local file path/to/myData.csv using each column as a serie
$DataSet->ImportFromCSV("path/to/myData.csv");
// .. setting the column separator to pipe
$DataSet->ImportFromCSV("path/to/myData.csv","|");
// .. import only the data from column 1
$DataSet->ImportFromCSV("path/to/myData.csv","|",1);
// .. import only the data from column 1,2 & 3
$DataSet->ImportFromCSV("path/to/myData.csv","|",array(1,2,3));
// .. the file contains an header that will be used to name the series
$DataSet->ImportFromCSV("path/to/myData.csv","|",array(1,2,3),TRUE);
// .. column 0 will be used as label for the horizontal axis
$DataSet->ImportFromCSV("path/to/myData.csv","|",array(1,2,3),TRUE,0);
.. for example, dealing with the following file :
ID |
January |
February |
March |
1 |
0 |
1 |
0.5 |
2 |
1.204119983 |
4 |
2 |
3 |
4.294091292 |
9 |
4.5 |
..and importing the data with the following command ( assuming separator character is a comma ):
$DataSet->ImportFromCSV("path/to/myData.csv",",",array(1,2,3),TRUE,0);
Will populate all the Data & DataStructure fields.
AddPoint
void AddPoint($Value,$Serie="Serie1",$Description="")
This function can be used to add one or multiple points to a data serie. By default points are added to Serie1.
// This will the value 25 as the last point of Serie1
$DataSet->AddPoint(25);
// This will the value 2,4,9,5,1,0 as the last point of Serie1
$DataSet->AddPoint(array(2,4,9,5,1,0));
// This will the value 12 as the last point of Serie2
$DataSet->AddPoint(12,"Serie2");
// .. and add the desciption "March" to the Serie2
$DataSet->AddPoint(12,"Serie2","March");
AddSerie
void AddSerie($SerieName="Serie1")
This function can be used to add a new data serie to the DataDescription object. All the series declared in this
object will be graphed when calling a chart function of the pChart class. There is no change on Data, only the
"Graphable" attribute is modified.
// Generate some data...
$DataSet->AddPoint(array(2,4,9,5,1,0),"Serie1");
$DataSet->AddPoint(array(1,1,2,2,3,3),"Serie2");
$DataSet->AddPoint(array(4,2,4,2,4,2),"Serie3");
// This will mark both Serie1 & Serie2 as "graphable" but not Serie3
$DataSet->AddSerie("Serie1");
$DataSet->AddSerie("Serie2");
AddAllSeries
void AddAllSeries()
This function can be used to set all data series as graphable. They'll all be graphed when calling a chart
function of the pChart class. There is no change on Data, only the "Graphable" attribute is modified.
// Generate some data...
$DataSet->AddPoint(array(2,4,9,5,1,0),"Serie1");
$DataSet->AddPoint(array(1,1,2,2,3,3),"Serie2");
// This will mark both Serie1 & Serie2 as "graphable"
$DataSet->AddAllSeries();
RemoveSerie
void RemoveSerie($SerieName="Serie1")
This function can be used to remove a data series from the graphable ones. They'll all be graphed when calling a chart
function of the pChart class. There is no change on Data, only the "Graphable" attribute is modified.
// Generate some data...
$DataSet->AddPoint(array(2,4,9,5,1,0),"Serie1");
$DataSet->AddPoint(array(1,1,2,2,3,3),"Serie2");
// This will mark both Serie1 & Serie2 as "graphable"
$DataSet->AddAllSeries();
// This will remove the "graphable" status of Serie2
$DataSet->RemoveSerie("Serie2");
SetAbsciseLabelSerie
void SetAbsciseLabelSerie($SerieName = "Name")
This function can be used to set which serie is used (if any) as abcisse value
// Generate some data...
$DataSet->AddPoint(array("Jan","Feb","Mar"),"Serie1");
$DataSet->AddPoint(array(2,4,9),"Serie2");
$DataSet->AddPoint(array(1,1,2),"Serie3");
// This will mark both Serie1 & Serie2 as "graphable"
$DataSet->AddSerie("Serie2");
$DataSet->AddSerie("Serie3");
// Set Serie as abcisse label
$DataSet->SetAbsciseLabelSerie("Serie1");
SetSerieName
void SetSerieName($Name,$SerieName="Serie1")
This function can be used to set the description of a serie. This description will be written on the
graph when calling the
drawLegend function
// Generate some data...
$DataSet->AddPoint(array(2,4,9),"Serie1");
$DataSet->AddPoint(array(1,1,2),"Serie2");
// This will set the name of Serie1 to "January"
$DataSet->SetSerieName("January");
// This will set the name of Serie2 to "February"
$DataSet->SetSerieName("February","Serie2");
SetXAxisName
void SetXAxisName($Name="X Axis")
This will give a name to the X axis, writting it horizontally behind the chart
// Give the label "Samples" to the X axis
$DataSet->SetXAxisName("Samples")
SetYAxisName
void SetYAxisName($Name="Y Axis")
This will give a name to the Y axis, writting it horizontally behind the chart
// Give the label "Temperature" to the Y axis
$DataSet->SetYAxisName("Temperature")
SetXAxisFormat
void SetXAxisFormat($Format="number")
With this function you can set the format of the X axis values. Todays formats are the following :
-
number used by defaults
-
time amount of seconds will be displayed as HH:MM:SS
-
date unix timestamp will be displayed as a date
-
metric number that will be displayed with k/m/g units
-
currency currency with custom unit
// Set X values format as date
$DataSet->SetXAxisFormat("date")
SetYAxisFormat
void SetYAxisFormat($Format="number")
With this function you can set the format of the Y axis values. Todays formats are the following :
-
number used by defaults
-
time amount of seconds will be displayed as HH:MM:SS
-
date unix timestamp will be displayed as a date
-
metric number that will be displayed with k/m/g units
-
currency currency with custom unit
// Set Y values format as date
$DataSet->SetYAxisFormat("metric")
SetXAxisUnit
void SetXAxisUnit($Unit="")
Set the axis unit. This will be appended to the axis values.
// Give the "km" unit to the X axis
$DataSet->SetXAxisUnit("km")
SetYAxisUnit
void SetYAxisUnit($Unit="")
Set the axis unit. This will be appended to the axis values.
// Give the "m/s" unit to the Y axis
$DataSet->SetYAxisUnit("m/s")
removeSerieName
void removeSerieName($SerieName)
This function can be used to remove the description of a serie. This description will be written on the
graph when calling the
drawLegend function. Removing
it's name using this function can be usefull to hide previously used series ( to
fill area for exemple )
// Generate some data...
$DataSet->AddPoint(array(2,4,9),"Serie1");
$DataSet->AddPoint(array(1,1,2),"Serie2");
// This will set the name of Serie1 to "January"
$DataSet->SetSerieName("January");
// This will set the name of Serie2 to "February"
$DataSet->SetSerieName("February","Serie2");
GetData
void GetData()
This function is used everytime you want to retrieve the Data stored in the pData structure
// Generate some data...
$DataSet->AddPoint(array(2,4,9),"Serie1");
$DataSet->AddPoint(array(1,1,2),"Serie2");
// This will display all the data stored in the DataSet
print_r($DataSet->GetData());
GetDataDescription
void GetDataDescription()
This function is used everytime you want to retrieve the Data description stored in the pData structure
// Generate some data...
$DataSet->AddPoint(array(2,4,9),"Serie1");
$DataSet->AddPoint(array(1,1,2),"Serie2");
// This will mark both Serie1 & Serie2 as "graphable"
$DataSet->AddAllSeries();
// This will set the name of Serie1 to "January"
$DataSet->SetSerieName("January");
// This will display all the data stored in the DataSet
print_r($DataSet->GetDataDescription());