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

Message ListMessage List     Post MessagePost Message

  Emphasize Grouping in xAxis
Posted by sinan on Mar-01-2013 07:53
Attachments:
Hi Peter,

the work is almost done. Only one issue remains. I have multiple pivot elements in one chart. In the picture there are 4 levels ( book ccy date system ). You can see that the first two label rows are placed and grouped perfectly. The issue starts with the items marked red.

I hate to say but in Excel in the've solved that rather elegantly - (2nd image). Can I do something similiar in cd? Probably it can be done with a data table but I could not find accurate examples.

Cheers
Sinan,
happy CD user.
test.jpg
test2.jpg

  Re: Emphasize Grouping in xAxis
Posted by Peter Kwan on Mar-02-2013 06:57
Attachments:
Hi sinan,

I have attached an example for your reference.

For each row of labels, if adjacent cells contain the same label, the code groups the cells together:

my $startRow = 0;
for (my $j = 0; $j < scalar(@$rowLabels); ++$j) {
    if (($j + 1 == scalar(@$rowLabels)) || ($rowLabels->[$j] ne $rowLabels->[$j + 1])) {
        $table->setCell($startRow, $i, $j - $startRow + 1, 1, $rowLabels->[$j]);
        $startRow = $j + 1;
   }
}

Then I enclose the above code in another loop that iterates through all the rows. In this way, all the rows are grouped.

Hope this can help.

Regards
Peter Kwan
multicylinder.png
multicylinder.pl
#!/usr/bin/perl
use perlchartdir;

my $data0 = [100, 125, 245, 147, 67, 96, 160, 145, 97, 167, 220, 125, 245, 147, 67, 96, 160, 145, 97, 167, 220, 125];
my $data1 = [85, 156, 179, 211, 123, 225, 127, 99, 111, 260, 175, 156, 179, 211, 123, 225, 127, 99, 111, 260, 175, 156];
my $labels = ["BOOK1", "BOOK2", "BOOK1", "BOOK1", "BOOK3", "BOOK4", "BOOK1", "BOOK2", 
	"BOOK3", "BOOK1",  "BOOK2", "BOOK1", "BOOK2", "BOOK1",  "BOOK1", "BOOK3",
	"BOOK4", "BOOK1",  "BOOK2", "BOOK3", "BOOK1", "BOOK2"];

my $labels2 = ["USD", "USD", "EUR", "JPY", "JPY", "JPY", "USD", "GBP", 
	"EUR", "JPY",  "JPY", "RUB", "RUB", "EUR",  "JPY", "EUR",
	"JPY", "GBP",  "GBP", "EUR", "JPY", "JPY"];

my $labels3 = ["2012-12-31", "2012-12-31", "2012-12-31", "2012-12-31", "2012-12-31", "2012-12-31", "2013-01-31", "2013-01-31", 
	"2013-01-31", "2013-01-31",  "2013-01-31", "2012-12-31", "2012-12-31", "2012-12-31",  "2012-12-31", "2012-12-31",
	"2012-12-31", "2013-01-31",  "2013-01-31", "2013-01-31", "2013-01-31", "2013-01-31"];
	
my $labels4 = ["System1", "System1", "System1", "System1", "System1", "System1", "System1", "System1", 
	"System1", "System1",  "System1", "System2", "System2", "System2",  "System2", "System2",
	"System2", "System2",  "System2", "System2", "System2", "System2"];

my $allLabels = [$labels, $labels2, $labels3, $labels4];

# Create a XYChart object of size 560 x 280 pixels.
my $c = new XYChart(1200, 700);

# Add a title to the chart using 14 pts Arial Bold Italic font
$c->addTitle("     Average Weekly Network Load", "arialbi.ttf", 14);

# Set the plotarea at (50, 50) and of 500 x 200 pixels in size. Use alternating light
# grey (f8f8f8) / white (ffffff) background. Set border to transparent and use grey
# (CCCCCC) dotted lines as horizontal and vertical grid lines
$c->setPlotArea(50, 50, 1140, 480, 0xffffff, 0xf8f8f8, $perlchartdir::Transparent,
    $c->dashLineColor(0xcccccc, $perlchartdir::DotLine), $c->dashLineColor(0xcccccc,
    $perlchartdir::DotLine));

# Add a legend box at (50, 22) using horizontal layout. Use 10 pt Arial Bold Italic
# font, with transparent background
$c->addLegend(60, 22, 0, "arialbi.ttf", 10)->setBackground($perlchartdir::Transparent
    );

# Set the x axis labels
$c->xAxis()->setLabels($allLabels->[0]);

$table = $c->xAxis()->makeLabelTable();
$table->getStyle()->setFontSize(10);
$table->getStyle()->setFontStyle("arialbd.ttf");
$table->getStyle()->setMargin(10);
$table->getRowStyle(0)->setFontAngle(90);

for(my $i = 1; $i < scalar(@$allLabels); ++$i) {
	$table->appendRow();
	$rowLabels = $allLabels->[$i];
	my $startRow = 0;
	for (my $j = 0; $j < scalar(@$rowLabels); ++$j) {
		if (($j + 1 == scalar(@$rowLabels)) || ($rowLabels->[$j] ne $rowLabels->[$j + 1])) {
			$table->setCell($startRow, $i, $j - $startRow + 1, 1, $rowLabels->[$j]);
	        $startRow = $j + 1;
        }
    }
}

# Draw the ticks between label positions (instead of at label positions)
$c->xAxis()->setTickOffset(0.5);

# Add axis title
$c->yAxis()->setTitle("Throughput (MBytes Per Hour)", "arialbd.ttf", 12);
$c->yAxis()->setLabelStyle("arialbd.ttf", 10);

# Set axis line width to 2 pixels
$c->xAxis()->setWidth(2);
$c->yAxis()->setWidth(2);

# Add a multi-bar layer with 3 data sets
my $layer = $c->addBarLayer2($perlchartdir::Side);
$layer->addDataSet($data0, 0xff6666, "Server #1");
$layer->addDataSet($data1, 0x8888ff, "Server #2");

# Set bar shape to circular (cylinder)
$layer->setBarShape($perlchartdir::CircleShape);

# Configure the bars within a group to touch each others (no gap)
$layer->setBarGap(0.2, $perlchartdir::TouchBar);

$c->packPlotArea(10, 50, $c->getWidth() - 10, $c->getHeight() - 10);

# Output the chart
$c->makeChart("multicylinder.png")


  Re: Emphasize Grouping in xAxis
Posted by sinan on Mar-02-2013 19:10
Oh dear, that simple?
Thank you!!!

Kind regards Sinan