|
Axis |
Posted by seafree on Feb-06-2016 05:58 |
|
Hi, I created a Chart with 2 axis, REAL & META for period 2011,2012,2013,2014 and 2015, when I showed the chart is perfect to 2011, 2013, 2014 and 2015 but not for 2012.
I create a random 2 arrays ($dat0 & $data1)and after I use the array:
$layer->addDataSet($data0, 0xff0000, "REAL")->setDataSymbol(
$perlchartdir::CircleSymbol, 7);
$layer->addDataSet($data1, 0x00ff00, "META")->setDataSymbol(
$perlchartdir::DiamondSymbol, 9);
for(my $i = 0; $i < scalar(@$data0); ++$i) {
$table->setText($i, 1, $data0->[$i]);
$table->setText($i, 2, $data1->[$i]);
}
The chart result is ok but when I selected year 2012 NOT DRAW AXIS $data0 (REAL) values, do you will know because it's happen only for year 2012.
The array data chart is correct created, but no show axis $data0, only show axis $data1
Would you help me?, please
Tkank you. |
Re: Axis |
Posted by Peter Kwan on Feb-09-2016 01:23 |
|
Hi seafree,
So you mean each of your chart is displaying data for one year. That means you have 5
charts for 2011, 2012, 2013, 2014 and 2015, but for some reasons, the chart for 2012 does
not have the line for REAL data. (I am not so sure what you mean by AXIS, as the code
you attached does not use two y-axes.)
If the problem is as mentioned above, from the code in your message, it seems the code
cannot distinguish whether your data are from 2012 or 2013 or from somewhere else. This
means the code cannot behave differently if your data are from 2012. This means the
problem may be related to the data values you are using.
It seems your code also include the data values in a table. Is it possible to attach the
resulting chart (which should have a table show the values), and also more details about
the charting part of the code to help diagnose the problem?
Regards
Peter Kwan |
Re: Axis |
Posted by seafree on Feb-09-2016 04:43 |
|
Hi Peter, Axis ares the lines data.
I created 2 arrays ($dat0 & $data1) and I'm sure the array are created because I'm printed it.
Of course I'm include the data values in a table and it's ok, charting part of the code is here:
# Create a XYChart
my $c = new XYChart(700, 335);
# Add a title
my $title = $c->addTitle(" ", "timesbi.ttf", 8);
# Set the plotarea
my $plotArea = $c->setPlotArea(50, 55, $c->getWidth() - 100, $c->getHeight() - 120,
$c->linearGradientColor(0, 55, 0, 55 + $c->getHeight() - 120, 0xffffff, 0xffffff
), -1, -1, $c->dashLineColor(0xaa000000, $perlchartdir::DotLine), -1);
# Add a legend box
my $legendBox = $c->addLegend($c->getWidth() / 2, $title->getHeight(), 0,
"arialbd.ttf", 10);
$legendBox->setAlignment($perlchartdir::TopCenter);
$legendBox->setBackground($perlchartdir::Transparent, $perlchartdir::Transparent);
# Set y-axis title
$c->yAxis()->setTitle(" % DCEV ", "arialbi.ttf", 10);
$c->yAxis()->setLabelStyle("arialbd.ttf", 8);
$c->yAxis()->setColors($perlchartdir::Transparent);
# Set y-axis
$c->yAxis()->setTickDensity(15);
# Add a line layer to the chart
my $layer = $c->addLineLayer2();
##axis scale from 93 to 100, with labels at .5
$c->yAxis()->setLinearScale(93, 100, .5);
# Set the line width to 3 pixels
$layer->setLineWidth(2);
# Add data sets to the line layer
$layer->addDataSet($data0, 0xff0000, "REAL")->setDataSymbol(
$perlchartdir::CircleSymbol, 7);
$layer->addDataSet($data1, 0x00ff00, "META")->setDataSymbol(
$perlchartdir::DiamondSymbol, 9);
# Set the x axis labels
$c->xAxis()->setLabels($labels);
# Convert the labels on the x-axis to a CDMLTable
my $table = $c->xAxis()->makeLabelTable();
# Set the default top/bottom margins of the cells to 3 pixels
$table->getStyle()->setMargin2(0, 0, 3, 3);
# Use Arial Bold as the font for the first row
$table->getRowStyle(0)->setFontStyle("arialbd.ttf");
# Add 2 more rows to the table.
$table->appendRow()->setBackground(0xeeeeee, $perlchartdir::LineColor);
$table->appendRow()->setBackground(0xeeeeee, $perlchartdir::LineColor);
# Put the values of the 2 data series to the cells in the 2 rows
for(my $i = 0; $i < scalar(@$data0); ++$i) {
$table->setText($i, 1, $data0->[$i]);
$table->setText($i, 2, $data1->[$i]);
}
# Insert a column on the left for the legend icons. Use 5 pixels left/right margins
# and 3 pixels top/bottom margins for the cells in this column.
$table->insertCol(0)->setMargin2(5, 5, 3, 3);
# The top cell is set to transparent, so it is invisible
$table->getCell(0, 0)->setBackground($perlchartdir::Transparent,
$perlchartdir::Transparent);
# The other 2 cells are set to the legend icons of the 2 data series
$table->setText(0, 1, $layer->getLegendIcon(0));
$table->setText(0, 2, $layer->getLegendIcon(1));
# Layout legend box first, so we can get its size
$c->layoutLegend();
# Adjust the plot area size.
$c->packPlotArea(1, $legendBox->getTopY() + $legendBox->getHeight(), $c->getWidth() - 1, $c->getHeight() - 1);
# After determining the exact plot area position, we may adjust the legend box and
# the title positions so that they are centered relative to the plot area (instead of
# the chart)
$legendBox->setPos($plotArea->getLeftX() + ($plotArea->getWidth() -
$legendBox->getWidth()) / 2, $legendBox->getTopY());
$title->setPos($plotArea->getLeftX() + ($plotArea->getWidth() - $title->getWidth()) /
2, $title->getTopY());
my $chart1URL = $c->makeTmpFile("/tmp/tmpcharts");
my $imageMap = $c ->getHTMLImageMap("","","title='{dataSetName}@{xLabel}:{value|0}'");
print <<EndOfHTML
<html>
<body bgcolor='#FFFFFF' topmargin='0' leftmargin='0'>
<center>
<div style="font-size:12pt; font-family:arial;">CEV - <b>
EndOfHTML
;
if ($p_subest eq 'EDO'){
$dir2.="EDO1";
} else{
$dir2.="EDO2";
}
if ($p_subest ne 'TODO'){
print "<a href=$dir2 target='_blank'>$nom{$p_subest}</a>";
} else{
print "<a href=$home target='_blank'>$nom{$p_subest}</a>";
}
print <<EndOfHTML
</b></div>
<div style="font-size:10pt; font-family:arial;"><b> ENERO-<font color="#C10434">$nom_meses[$p_mes-1]</font> $p_anio</b></div>
<img src="getchart.pl?img=/tmp/tmpcharts/$chart1URL" border="0" usemap="#map1">
<map name="map1"> $imageMap </map></center>
<table align=center border=0 cellspacing=0>
<TR>
<TD COLSPAN=1>
<center><input type=button style="font:arial; color:#ffffff; background:#639c18" value="Regresar" name="regresar" OnClick='history.back()' style='background-color:#7495ab; color:#fff;'>
</TD>
</TR>
</table>
</body>
</html>
EndOfHTML
;
data0 and data1 is created because a I'm printing it before show the chart
Could you help?, please.
Regards
Seafree |
Re: Axis |
Posted by Peter Kwan on Feb-09-2016 10:59 |
|
Hi seafree,
There are many reasons why a line does not display because of the data. For example,
from your full code, I see that the y-axis is configured to be 93 to 100, so the line would
not appear unless it is within 93 to 100. Or the two lines can have the same data, and so
the two lines overlap and so only one line is visible, etc..
Also, it is not clear from your the code if $data0 and $data1 contains numbers of text
strings. If something is printed as "11.9", it can be a number of text string and it is
indistinguishable just from the print out. Although Perl can convert a string to a number
automatically, the "11.9" may not be considered as a valid number depending on locale
(eg., in some locale, the decimal separator is a comma, not a dot).
If some chart images are available for the charts that can display both series, and the
chart that can only display one series, we can examine what are the data that can cause
this problem.
I see that your code also produces an image map. It can also provide useful information
for analysis.
If you cannot attach the charts in a public forum, is it possible to email them to be at
pkwan@advsofteng.net?
Regards
Peter Kwan |
Re: Axis |
Posted by seafree on Feb-12-2016 01:32 |
|
Hi Peter,
I probably find solution but I don't how to do it, I founded you forum respons about it, Posted by Frank on Apr-22-2005 05:41 where you suggested using: The code is (in VBScript):
Call c.yAxis().setRounding(0, 0)
ChartDirector Support:
http://www.chartdir.com/forum/download_thread.php?bn=chartdir_support&pattern=&thread=1114162911
I suppose my problem is like that but I don't how use SETROUNDING in perl, could you help me please.
Thanks a lot Peter.
Regards
Seafree |
Re: Axis |
Posted by Peter Kwan on Feb-12-2016 03:43 |
|
Hi seafree,
The setRounding is only for axis automatically scaled by ChartDirector. It tells
ChartDirector whether to "round" the axis end points to the label position. The code in Perl
is:
$c->yAxis()->setRounding(0, 0);
The code has no effect for your case, because in your case, your code already fully specify
the axis scale using "$c->yAxis()->setLinearScale(93, 100, .5);", so there is nothing
ChartDirector can adjust or modify.
If you want ChartDirector to automatically determine the axis scale, please remove the
line "$c->yAxis()->setLinearScale(93, 100, .5);". You can use Axis.setAutoScale,
Axis.setRounding, Axis.setTickDensity and Axis.setMinTickInc to fine tune how
ChartDirector automatically determine the axis scale.
Hope this can help.
Regards
Peter Kwan |
Re: Axis |
Posted by seafree on Feb-12-2016 04:37 |
|
Hi Peter,
You have reason, the code have not effect for my case.
The user give me know his decision about how show the charts, after that I will use: Axis.setAutoScale,Axis.setRounding, Axis.setTickDensity and Axis.setMinTickInc.
Or definitely use: $c->yAxis()->setLinearScale(93, 100, .5) with others values.
Thanks a lot Peter.
Regards
Seafree |
|