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

Message ListMessage List     Post MessagePost Message

  Issues with marks on multigraph and legend box
Posted by Greg White on Nov-08-2011 05:44
Attachments:
In the three graphs that I have attached, the one labeled Weight is being drawn correctly.  On the age graph the marks are showing up "behind" the bars on this multi-graph report (female 40-49 is most obvious), and I cannot get the center labels of age ranges to center (when I move them left, the blue bars get cut off).  On the Assessments graph, the legend box is showing "Health Risk", and I don't want that to show, only "Comparitive Group" as is showing correctly in the Weight levels.

I am using version 5.0, with Perl, on a FreeBSD server.

The code for creating the Weight and Assessment graphs is very similar, just not getting the same results.  The mark part of the multigraph is just like the weight graph but we have the extra step of the multigraph which I assume is messing up the layering and causing the marks to go to the back.

I followed the example code to create these to meet my needs.
1320671297_ggr_age.png
1320671297_ggr_ta.png
1320671297_ggr_wt.png

  Re: Issues with marks on multigraph and legend box
Posted by Peter Kwan on Nov-09-2011 00:17
Hi Greg,

For the "marks behind the bars", is it possible you have reverse the order of adding the box-whisker layer and the bar layer? By default, you would need to add the box-whisker layer first, and the bar layer after that, so that the box-whisker symbols will stay in front of the bars. In ChartDirector Ver 5.x, you may also use Layer.moveFront to move a layer in front of another layer. (For your case, moving layers is necessary only if you add the bar layer first.)

For the "blue bars get cut off" problem, it is probably because your pink chart has a non-transparent background, and that it is moved so that it overlaps with the blue chart, and that the pink chart is in front of the blue chart. You may solve the problem by changing any of the above factors.

As I do not have your code, I cannot see where are the borders of the blue and pink charts. I just guess the pink chart is drawn with a wide "left margin" (of around 75 pixels). If this is the case, you can set the labels box width to be 75 pixels as well. (In the current code, it seems the label box is 50 pixels width.)

In the original "Dual Horizontal Bar Charts" sample code that comes with ChartDirector, there are the following lines of code:

# Set the labels between the two bar charts, which can be considered as the x-axis
# labels for the right chart
my $tb = $c->xAxis()->setLabels($labels);

# Use a fix width of 50 for the labels (height = automatic) with center alignment
$tb->setSize(50, 0);

Please change the 50 above to 75.

If the above still does not solve the problem, would you mind to modify your code to add a non-transparent border to the pink and blue charts, so I can see their boundaries?

For the legend box in the "Assessments" chart, the "Health Risk" is there probably because your code has provided that name to ChartDirector as the name of the data set. If you do not provide that name, then the legend box will not have "Health Risk".

For example, instead of:

$c->addBarLayer($myData, $myColor, "Health Risk");

you may use:

$c->addBarLayer($myData, $myColor);

Another method is to explicitly ask ChartDirector not to insert the name into the legend box using Layer.setLegendOrder, like:

$layer = $c->addBarLayer($myData, $myColor, "Health Risk");
$layer->setLegendOrder($perlchartdir::NoLegend);

Hope this can help.

Regards
Peter Kwan

  Re: Issues with marks on multigraph and legend box
Posted by Greg White on Nov-09-2011 01:06
Attachments:
Marks behind bars, it WAS in the same order as the weight graph which is working properly, so I reversed the order, it still gave the same results.  Also the graphs are being generated in transparent mode:  Here is the code snippet for this graph:

my $c = new XYChart(250, $bar_charthigh, $perlchartdir::Transparent);
my $c1 = new XYChart(250, $bar_charthigh, $perlchartdir::Transparent);

$c->setPlotArea(50, 0, 180, 205, $perlchartdir::Transparent, -1, $perlchartdir::Transparent, 0xe0e0e0);

$c1->setPlotArea(50, 0, 180, 205, $perlchartdir::Transparent, -1, $perlchartdir::Transparent, 0xe0e0e0);

# Swap the axis so that the bars are drawn horizontally
$c->swapXY(1);
$c1->swapXY(1);
$c1->yAxis()->setReverse();

$c->addText(248, 0, "Female", "arial.ttf", 11, 0xcfa9cf)->setAlignment($perlchartdir::TopRight);
$c1->addText(20, 0, "Male", "arial.ttf", 11, 0x9bb1be);

# $textbox->setFontStyle("arial.ttf");
# $textbox->setFontSize(7);
$c->yAxis()->setLabelFormat("{value}%");
$c1->yAxis()->setLabelFormat("{value}%");

# Set the y axis label font to Arial Bold
$c->yAxis()->setLabelStyle("arial.ttf");
$c1->yAxis()->setLabelStyle("arial.ttf");

my $tb = $c->xAxis()->setLabels($labels);
$tb->setSize(50, 0);
$tb->setAlignment($perlchartdir::Center);

# Set the label font to Arial Bold
$tb->setFontStyle("arial.ttf");

# Disable ticks on the x-axis by setting the tick length to 0
$c->xAxis()->setTickLength(0);
$c1->xAxis()->setTickLength(0);

my $femalelayer = $c->addBarLayer2($perlchartdir::Stack);
$femalelayer->addDataSet($female_data, 0xcfa9cf, "Females");
$femalelayer->setBorderColor(0xcfa9cf);
$c->addLineLayer($male_data, $perlchartdir::Transparent);

if($isComparative && $comp_age_basis){
$markLayer = $c->addBoxWhiskerLayer(undef, undef, undef, undef, $comp_female_data, -1, 0x333333);
$markLayer->setLineWidth(2);
$labellayer = $c->addBarLayer($data, $perlchartdir::Transparent);   $labellayer->setBarGap($bargap);
$labellayer->setBorderColor($perlchartdir::Transparent);
}

my $malelayer = $c1->addBarLayer2($perlchartdir::Stack);
$malelayer->addDataSet($male_data, 0x9bb1be, "Males");
$malelayer->setBorderColor(0x9bb1be);
$c1->addLineLayer($female_data, $perlchartdir::Transparent);

if($isComparative && $comp_age_basis){
$mmarkLayer = $c1->addBoxWhiskerLayer(undef, undef, undef, undef, $comp_male_data, -1, 0x333333);
$mmarkLayer->setLineWidth(2);
$mlabellayer = $c1->addBarLayer($data, $perlchartdir::Transparent);   $mlabellayer->setBarGap($bargap);
$mlabellayer->setBorderColor($perlchartdir::Transparent);
}

# Create a MultiChart object of size 590 x 320 pixels.
my $m = new MultiChart(530, 270, 0xffffff);

# Add a title to the chart using Arial Bold Italic font
my $title = $m->addTitle("Age groups", "arial.ttf");

if($isComparative && $comp_age_basis){
$legendBox = $m->addLegend($m->getWidth() / 2, $title->getHeight()-12, "arial.ttf", 8);
$legendBox->setBackground($perlchartdir::Transparent, $perlchartdir::Transparent);
$legendBox->setAlignment($perlchartdir::TopCenter);
$legendBox->setLineStyleKey();
$legendBox->addKey("Comparative Group", 0x333333, 2);
}
# Add another title at the bottom using Arial Bold Italic font
$m->addTitle2($perlchartdir::Bottom, "Percentage of Participants", "arial.ttf", 10);

# Put the left chart at (0, 25)
$m->addChart(0, 25, $c1);

# Put the right chart at (270, 25)
$m->addChart(256, 25, $c);


For the assessments graph the NoLegend worked perfectly.
1320748665_ggr_age.png

  Re: Issues with marks on multigraph and legend box
Posted by Peter Kwan on Nov-09-2011 01:42
Attachments:
Hi Greg,

I have just tried your code by putting in some artificial data. I found the marks work normally if I reverse the order of the layers. Also, I found that moving the labels do not cut off the blue bars at all. Below please find my test code for your reference.

Hope this can help.

Regards
Peter Kwan


# The age groups
my $labels = ["0 - 4", "5 - 9", "10 - 14", "15 - 19", "20 - 24", "24 - 29",
    "30 - 34", "35 - 39", "40 - 44", "44 - 49", "50 - 54", "55 - 59", "60 - 64",
    "65 - 69", "70 - 74", "75 - 79", "80+"];

# The male population (in thousands)
my $male_data = [215, 238, 225, 236, 235, 260, 286, 340, 363, 305, 259, 164, 135, 127,
    102, 68, 66];

# The female population (in thousands)
my $female_data = [194, 203, 201, 220, 228, 271, 339, 401, 384, 304, 236, 137, 116, 122,
    112, 85, 110];


my $comp_female_data = [100, 100, 100, 100, 100, 100, 100, 100];
my $comp_male_data = [100, 100, 100, 100, 100, 100, 100, 100];
my $data = [100, 100, 100, 100, 100, 100, 100, 100];

my $bar_charthigh = 250;
my $isComparative = 1;
my $comp_age_basis = 1;


my $c = new XYChart(270, $bar_charthigh, $perlchartdir::Transparent);
my $c1 = new XYChart(250, $bar_charthigh, $perlchartdir::Transparent);

$c->setPlotArea(70, 0, 180, 205, $perlchartdir::Transparent, -1, $perlchartdir::Transparent, 0xe0e0e0);

$c1->setPlotArea(50, 0, 180, 205, $perlchartdir::Transparent, -1, $perlchartdir::Transparent, 0xe0e0e0);

# Swap the axis so that the bars are drawn horizontally
$c->swapXY(1);
$c1->swapXY(1);
$c1->yAxis()->setReverse();

$c->addText(248, 0, "Female", "arial.ttf", 11, 0xcfa9cf)->setAlignment($perlchartdir::TopRight);
$c1->addText(20, 0, "Male", "arial.ttf", 11, 0x9bb1be);

# $textbox->setFontStyle("arial.ttf");
# $textbox->setFontSize(7);
$c->yAxis()->setLabelFormat("{value}%");
$c1->yAxis()->setLabelFormat("{value}%");

# Set the y axis label font to Arial Bold
$c->yAxis()->setLabelStyle("arial.ttf");
$c1->yAxis()->setLabelStyle("arial.ttf");

my $tb = $c->xAxis()->setLabels($labels);
$tb->setSize(70, 0);
$tb->setAlignment($perlchartdir::Center);

# Set the label font to Arial Bold
$tb->setFontStyle("arial.ttf");

# Disable ticks on the x-axis by setting the tick length to 0
$c->xAxis()->setTickLength(0);
$c1->xAxis()->setTickLength(0);
$c->xAxis()->setColors($perlchartdir::Transparent);

if($isComparative && $comp_age_basis){
$markLayer = $c->addBoxWhiskerLayer(undef, undef, undef, undef, $comp_female_data, -1, 0x333333);
$markLayer->setLineWidth(2);
$labellayer = $c->addBarLayer($data, $perlchartdir::Transparent);   $labellayer->setBarGap($bargap);
$labellayer->setBorderColor($perlchartdir::Transparent);
}

my $femalelayer = $c->addBarLayer2($perlchartdir::Stack);
$femalelayer->addDataSet($female_data, 0xcfa9cf, "Females");
$femalelayer->setBorderColor(0xcfa9cf);
$c->addLineLayer($male_data, $perlchartdir::Transparent);

if($isComparative && $comp_age_basis){
$mmarkLayer = $c1->addBoxWhiskerLayer(undef, undef, undef, undef, $comp_male_data, -1, 0x333333);
$mmarkLayer->setLineWidth(2);
$mlabellayer = $c1->addBarLayer($data, $perlchartdir::Transparent);   $mlabellayer->setBarGap($bargap);
$mlabellayer->setBorderColor($perlchartdir::Transparent);
}

my $malelayer = $c1->addBarLayer2($perlchartdir::Stack);
$malelayer->addDataSet($male_data, 0x9bb1be, "Males");
$malelayer->setBorderColor(0x9bb1be);
$c1->addLineLayer($female_data, $perlchartdir::Transparent);

# Create a MultiChart object of size 590 x 320 pixels.
my $m = new MultiChart(530, 270, 0xffffff);

# Add a title to the chart using Arial Bold Italic font
my $title = $m->addTitle("Age groups", "arial.ttf");

if($isComparative && $comp_age_basis){
$legendBox = $m->addLegend($m->getWidth() / 2, $title->getHeight()-12, "arial.ttf", 8);
$legendBox->setBackground($perlchartdir::Transparent, $perlchartdir::Transparent);
$legendBox->setAlignment($perlchartdir::TopCenter);
$legendBox->setLineStyleKey();
$legendBox->addKey("Comparative Group", 0x333333, 2);
}
# Add another title at the bottom using Arial Bold Italic font
$m->addTitle2($perlchartdir::Bottom, "Percentage of Participants", "arial.ttf", 10);

# Put the left chart at (0, 25)
$m->addChart(0, 25, $c1);

# Put the right chart at (270, 25)
$m->addChart(235, 25, $c);
dualhbar.png

  Re: Issues with marks on multigraph and legend box
Posted by Greg White on Nov-09-2011 03:52
Peter,
Thanks!  Your example has me close enough that I can tweak it the rest of the way.

Greg