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

Message ListMessage List     Post MessagePost Message

  horizontal bar labels and values overlapping
Posted by Leo on Apr-08-2012 09:55
Attachments:
Hey, Peter,

I have a generic perl that generates bar charts, the incoming data is dynamic, different
data length, different label length, data could be positve or negative, some labels longer
than others...

I was unable to solve the problem as circled below.

I tried different permutations of plot sizes and xy coordinates, but no luck.

Any suggestions?

code:

!/usr/bin/perl
use perlchartdir;

my $data = [DATAPTS];

my $labels = [LABELPTS];

my $c = new XYChart(350, 250);

$c->setPlotArea(200, 10, 120, 230, $perlchartdir::Transparent,
$perlchartdir::Transparent, $perlchartdir::Transparent, $perlchartdir::Transparent,
$perlchartdir::Transparent);

my $layer = $c->addBarLayer($data, 0x000099);

$c->swapXY(1);

$layer->setBarGap(0.2);

$layer->setAggregateLabelFormat(" {value}%");

$layer->setAggregateLabelStyle("arialbd.ttf", 12, 0x000000);

my $textbox = $c->xAxis()->setLabels($labels);

$textbox->setFontStyle("arialbd.ttf");

$textbox->setFontSize(13);

$c->xAxis()->setColors($perlchartdir::Transparent, 0x000000);

$c->yAxis()->setColors($perlchartdir::Transparent, $perlchartdir::Transparent);

$c->makeChart("1_BARPNG")
peter5.png

  Re: horizontal bar labels and values overlapping
Posted by Peter Kwan on Apr-10-2012 01:35
Hi Leo,

You may consider to first check if there are negative values, and add an axis margin (using Axis.setMargin) if there are negative values. This may be something like:

for my $value (@$data) {
    if ($value < 0) {
         $c->yAxis()->setMargin(0, 30);
         break;
    }
}

(*** Note ***: I have not tested the code above.)

Regards
Peter Kwan

  Re: horizontal bar labels and values overlapping
Posted by Leo on Apr-10-2012 05:01
Thanks, it works...

Peter, couple more questions:

1. how do I left justified the labels (percentages stay)?
2. how do I make just the negative bars *and* the percentages red?

  Re: horizontal bar labels and values overlapping
Posted by Peter Kwan on Apr-11-2012 01:30
Hi Leo,

1. how do I left justified the labels (percentages stay)?

I assume you are referring to the x-axis labels.

First, you need to determine where to "left justify" to. Suppose you would like to left justify with respect to the left edge of the chart. First, you may set the TextBox containing the labels so that the left edge of the TextBox is at the left side of the chart. Then you may use TextBox.setAlignment to align the text to the left side. It is like:

$t = $c->xAxis()->setLabelStyle("arialbd.ttf", 10);
$t->setSize($c->getPlotArea()->getLeftX(), 0);
$t->setAlignment($perlchartdir::Left);

2. how do I make just the negative bars *and* the percentages red?

You may refer to the sample code "Positive Negative Bars" for an example.

Hope this can help.

Regards
Peter Kwan