问题
I want to use pChart to render a simple line graph of a sample value vs. the date. I have the basics working, but how do I handle gaps in the date? The samples are already averaged by the quarter year, but not every quarter has a sample. Sometimes it skips a quarter or two.
Currently, these gaps are compressed on the X axis one after another, instead of being spaced out in their natural order in a number line.
The data is coming from a MySQL database. I'm probably missing something simple. Can anyone help?
#Array variables.
$date = "";
$value = "";
#Fetch the database rows, and sort them into arrays.
while ($row = mysql_fetch_array($result))
{
$date[] = $row["date"];
$value[] = $row["value"];
}
#Create a chart data object.
$MyData = new pData();
#Pass the data to the chart.
$MyData->addPoints($date, "Date");
$MyData->addPoints($value, "Value");
#Configure labels.
$MyData->setAxisName(0,"Value");
#Set the date as the X axis.
$MyData->setAbscissa("Date");
$MyData->setAbscissaName("Date");
回答1:
This is trying to use the drawLineChart()
function, when it should be using the drawScatterLineChart()
function. The differences aren't very well explained, but are crucial.
A "Line Chart" doesn't use a number line for its independent axis. It's used for charts with a non-numerical axis, like months of the year. This axis doesn't register gaps like a natural number line would, because text doesn't necessarily have values which can be ordered in a logical way.
The "Scatter Line Chart" is a normal XY chart with proper number lines on its axes. It responds to gaps in values like one would expect. This should really be the default example in the documentation.
来源:https://stackoverflow.com/questions/33208323/pchart-timeline-with-gaps