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

Message ListMessage List     Post MessagePost Message

  bar chart bar no show
Posted by Leo on Apr-18-2012 00:29
Attachments:
Hello, Peter,

1. the bar chart below has no bars associated with 2% and 1%, however, -2% did show
2. I was able to make the negative bars red, although I managed to have the negative
labels red

code:
#!/usr/bin/perl
use perlchartdir;
my $data = [25.4,-37,-35,-7,-2,1,2,100];
my $labels = ["NET PROFIT","COGS","SGA Exp","Income Tax","Amort. Intangibles","Equity
In Affiliates","Other Operating Exp","Revenue"];
my $c = new XYChart(350, 250);
$c->setPlotArea(190, 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.3);
$layer->setAggregateLabelFormat(" {value}%");
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); $layer-
>setAggregateLabelStyle("arialbd.ttf", 13, $layer->yZoneColor(0, 0xff0000, 0x000044));
$c->yAxis()->setMargin(0, 25);
$c->makeChart("pbar.20104.png")
peter7.png

  Re: bar chart bar no show
Posted by Peter Kwan on Apr-19-2012 01:50
Attachments:
Hi Leo,

The current version of ChartDirector does not display bars that are less than 1 pixel wide. So some bars may not be visible. (In most cases, this is not noticible because a 1-pixel bar will be overlapped by the x-axis and not visible in any case, but in your case the x-axis is transparent.)

To make non-zero bars visible, one method is to use a box-whisker layer.

I have modified the code which should achieve what you need. The bars have two colors - red and blue - depending on whether it is positive and negative, and all non-zero bars are visible.

Hope this can help.

Reards
Peter Kwan

#!/usr/bin/perl
use perlchartdir;

my $data = [25.4,-37,-35,-7,-2,1,2,100];
my $labels = ["NET PROFIT","COGS","SGA Exp","Income Tax","Amort. Intangibles","Equity In Affiliates","Other Operating Exp","Revenue"];

my $c = new XYChart(350, 250);
$c->setPlotArea(190, 10, 120, 230, $perlchartdir::Transparent,$perlchartdir::Transparent, $perlchartdir::Transparent,$perlchartdir::Transparent, $perlchartdir::Transparent);
$c->swapXY(1);

my $posData = new ArrayMath($data)->selectGTZ(undef, $perlchartdir::NoValue)->result();
my $negData = new ArrayMath($data)->selectLTZ(undef, $perlchartdir::NoValue)->result();

my $layer = $c->addBoxWhiskerLayer(undef, undef, undef, undef, $posData, 0x000099, 0x000099, 0x000099);
$layer->setDataGap(0.3);
$layer->setLineWidth(2);

my $layer = $c->addBoxWhiskerLayer(undef, undef, undef, undef, $negData, 0xff0000, 0xff0000, 0xff0000);
$layer->setDataGap(0.3);

my $layer = $c->addBarLayer2($perlchartdir::Overlay);
$layer->setBarGap(0.3);
$layer->setBorderColor($perlchartdir::SameAsMainColor);
$layer->addDataSet($posData, 0x000099);
$layer->addDataSet($negData, 0xff0000);
$layer->setAggregateLabelFormat(" {value}%");
$layer->setAggregateLabelStyle("arialbd.ttf", 13, $layer->yZoneColor(0, 0xff0000, 0x000044));

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->yAxis()->setMargin(0, 25);$c->makeChart("pbar.20104.png")

$c->makeChart("pbar.20104.png")
simplebar.png

  Re: bar chart bar no show
Posted by Leo on Apr-19-2012 06:56
Great! Thanks, Peter.