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

Message ListMessage List     Post MessagePost Message

  Bar chart with customized bar color
Posted by Jorge Eduardo on Sep-05-2013 05:09
Attachments:
Hi Peter,  I want to know if it's possible to color one bar,  just one in a particular color?
Like the above image,  where the last bar which represents the sum of values is colored
different.

Thanks in advance,

Jorge
chr_bar_01_cur.png

  Re: Bar chart with customized bar color
Posted by Jorge Eduardo on Sep-05-2013 05:18
Hi Peter,  I've just checked the multi color bar chart in chardirector documentation,  but
didn't get how to customize the last bar.

Thanks,  Jorge

  Re: Bar chart with customized bar color
Posted by Wes G on Sep-05-2013 13:03
Jorge:

Depending on your language, you need to create an array of colors and then use
addBarLayer3()

If you want the first two to be the same color, just put that color in there twice.

data = [1,2,3]
colors = [0xFF0000, 0xFF0000, 0x00FF00]   # red, red, green

c = ChartDirector::XYChart.new(300, 220, ChartDirector::goldColor(), -1, 2)
c.setPlotArea(40, 40, 240, 150)
c.addBarLayer3(data, colors)

  Re: Bar chart with customized bar color
Posted by Jorge Eduardo on Sep-06-2013 06:07
Hi Peter,  it works well if I have a fixed number of bars,  but I have a variable number of
values in the data array.  Is there any script I can use in order to force the last value in
the arry to be custom colored.

Thanks,  Jorge

  Re: Bar chart with customized bar color
Posted by Jorge Eduardo on Sep-06-2013 06:07
Hi Peter,  it works well if I have a fixed number of bars,  but I have a variable number of
values in the data array.  Is there any script I can use in order to force the last value in
the arry to be custom colored.

Thanks,  Jorge

  Re: Bar chart with customized bar color
Posted by Peter Kwan on Sep-06-2013 23:42
Jo Jorge,

If your code creates a data array with a variable number of values, it can also create an array with a variable number of colors. You can always force the last color to be different from the other colors. For example:

int[] colors = new int[myData.length];
Arrays.fill(colors, 0xff0000);   // all bars are of the same color
colors[myData.length - 1] = 0x0000ff;   // except the last bar which is of a different color

c.addBarLayer3(myData, colors)

Hope this can help.

Regards
Peter Kwan