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

Message ListMessage List     Post MessagePost Message

  Changing color of 3D bars?
Posted by Gelfling on May-02-2012 07:53
I want a chart with 3 bars.

First bar is red, then next one is blue, then green.

How do I dictate this using the multi-color 3d chart?  It looks great, but I want to control the colors.


# The data for the bar chart
my $data = [$perlchartdir::NoValue,170, 180,172, $perlchartdir::NoValue];

# The labels for the bar chart
my $labels = ["", "2011", "2012", "2013",""];

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

# Set the plotarea at (50, 40) with alternating light grey (f8f8f8) / white (ffffff)
# background
$c->setPlotArea(50, 40, 400, 200, 0xf8f8f8, 0xffffff);

# Add a title to the chart using 14 pts Arial Bold Italic font
$c->addTitle("    Bar Shape Demonstration", "arialbi.ttf", 14);


# Add a multi-color bar chart layer
my $layer = $c->addBarLayer3($data,[0xffffff]);


# Set layer to 3D with 10 pixels 3D depth
$layer->set3D(10);

# Set the first bar (index = 0) to square shape
$layer->setBarShape($perlchartdir::SquareShape, 0, 0);


# Set the labels on the x axis.
$c->xAxis()->setLabels($labels);
#$c->xAxis->setLinearScale(0,10,$perlchartdir::NoValue,$perlchartdir::NoValue);

# Add a title to the y axis
$c->yAxis()->setTitle("Frequency");

# Add a title to the x axis

  Re: Changing color of 3D bars?
Posted by Peter Kwan on May-03-2012 01:27
Hi Gelfling,

You may refer to the sample code "Multi-Color Bar Chart" that comes with ChartDirector. In this example, the colors of the bars are specified by using an array of colors (rather than using the default colors).

For your case, the code should be like:

my $colors = [0, 0xff0000, 0x0000ff, 0x00ff00, 0];
my $layer = $c->addBarLayer3($data, $colors);

Hope this can help.

Regards
Peter Kwan