ASE Home Page Products Download Purchase Support About ASE
ChartDirector General
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  XYChart using setDateScale,I got a blank chart.
Posted by William on Apr-28-2013 11:42
Hello~
I try to modify simpleline.php for testing method setDateScale(),but the result isn't right.

My code:
<?php
require_once("../lib/phpchartdir.php");

# The data for the line chart
$data = array(30, 28, 40, 55, 75, 68, 54, 60, 50, 62, 75, 65, 75, 91, 60, 55, 53, 35,
    50, 66, 56, 48, 52, 65, 62);

# The labels for the line chart
//$labels = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12",
//    "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24");

# Create a XYChart object of size 250 x 250 pixels
$c = new XYChart(1024, 768);
for ($i=1;$i<=25;$i++) {
$labels[] = $c->formatValue(chartTime(2013, 4, $i),"{value|mm-dd-yyyy}");
}
# Set the plotarea at (30, 20) and of size 200 x 200 pixels
$c->setPlotArea(30, 20, 900, 700);

# Add a line chart layer using the given data


# Set the labels on the x axis.
$c->xAxis->setLabels($labels);

# Display 1 out of 3 labels on the x-axis.
$c->xAxis->setLabelStep(3);
$c->xAxis->setDateScale(chartTime(2013, 4, 10), chartTime(2013, 4, 15));

$c->addLineLayer($data);
//$c->addTrendLayer($data);
# Output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));
?>
The xAxis's DateScale is right(from 04/10/2013 to 04/15/2013),but no any line be showed
in the chart.

Thx a lot for helping~ :)

  Re: XYChart using setDateScale,I got a blank chart.
Posted by Peter Kwan on Apr-29-2013 11:53
Hi William,

If you use Axis.setDateScale (or Axis.setLinearScale or Axis.setLogScale), then you do not need to use Axis.setLabels (they are contradictory). Instead, you would need to use Layer.setXData to provide ChartDirector the x-coordinates of your data.

For example, in your case, your x-axis scale is to Apr 10, 2013 00:00:00 to Apr 15, 2013 00:00:00, which has a duration of 5 days. Your data have 25 data points. It is not clear how you would like to put the data points on the chart. (ChartDirector will not automatically spread your points evenly.) If you would like to spread your 25 points evenly in on the 5 days axis, then the duration between each point will be 5 hours. In this case, you may use:

for ($i=0; $i < 25; $i++)
    $xCoor[] = chartTime(2013, 4, 1) + 5 * 3600 * i;

The charting code is then:

$c = new XYChart(1024, 768);
$c->setPlotArea(30, 20, 900, 700);

$c->xAxis->setDateScale(chartTime(2013, 4, 10), chartTime(2013, 4, 15), 86400, 14400);
$c->xAxis->setLabelFormat("{value|mm-dd-yyyy}");

$layer = $c->addLineLayer($data);
$layer->setXData($xCoor);

# Output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));
?>

Hope this can help.

Regards
Peter Kwan

  Re: XYChart using setDateScale,I got a blank chart.
Posted by William on Apr-29-2013 19:45
Attachments:
thx for your helping~
I understand how to using the mothed (setDateScale & setXData) from your reply.

In fact, I want to limit display data in XYchart.
For example:
# data for the line chart
$data = array(30, 28, 40, 55, 75, 68, 54, 60, 50, 62, 75, 65, 75, 91, 60, 55, 53,
35,50, 66, 56, 48, 52, 65, 62);

# associated array
for ($i=1; $i <= count($data; $i++){
$timestamps[] = chartTime(2013, 4, $i);
}
both of two arrays has 25 items,I want to the display some items in the arrays,but I
don't
want to modify the arrays.
so I try to use the methed setDateScale().

My charting code:
$c = new XYChart(1024, 768);
$c->setPlotArea(30, 20, 900, 700);

$c->xAxis->setDateScale(chartTime(2013, 4, 5), chartTime(2013, 4, 15), 86400);
$c->xAxis->setLabelFormat("{value|mm-dd-yyyy}");

$layer = $c->addLineLayer($data);
$layer->setXData($xCoor);

# Output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));

but the chart is display outside of DateScale's data,see the attachment.
how to fix the problem?
setdate.png

  Re: XYChart using setDateScale,I got a blank chart.
Posted by Peter Kwan on Apr-29-2013 21:07
Hi William,

In your code, the x-coordinates of your data are from 2013-4-1 to 2013-4-25. However, your have configured the x-axis to be from 2013-4-5 to 2013-4-15. So it is normal the data will exceed the axis range? Would you mind to clarify what would you want the chart should look like?

If you want the x-axis range to be from 2013-4-1 to 2013-4-25 (or a range that matches with your data), simply remove the setDateScale line. ChartDirector will auto-scale the x-axis to match with your data. Of course, you can also set the x-axis range from chartTime(2013, 4, 1) to chartTime(2013, 4, 25).

If you only want to display the data that is within the axis range, you may:

(1) Remove the data that are outside the axis range before passing the data to ChartDirector.

or

(2) Use XYChart.setClipping to clip the data to the plot area.

Hope this can help.

Regards
Peter Kwan

  Re: XYChart using setDateScale,I got a blank chart.
Posted by William on Apr-29-2013 21:26
thx very~
Mothed setClipping() is the way that I want.

ChartDirector is really useful Chart component,I will test it for more features.