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

Message ListMessage List     Post MessagePost Message

  Order / Change Bar-Position
Posted by Tom on Nov-24-2014 21:34
Attachments:
Hi,
I've a little problem.

How can I change the position of the bars?
The grey bar should be displayed always in front of the multi-color-bar. (Values of the previous week without color)

Example:

[code]
<%@page import="ChartDirector.*" %>
<%
double[] data = {85, 156, 179.5, 211, 123}; //multicolor values
String[] labels = {"Mon", "Tue", "Wed", "Thu", "Fri"};
int[] colors = {0xff0000, 0x00ff00, 0xffff00, 0xff0000, 0x00ff00};
XYChart c = new XYChart(210, 170);
c.setPlotArea(0, 0, 200, 150);

/*** Test add color&grey bars ***/
BarLayer barlayer = c.addBarLayer3(data, colors);
barlayer.addDataGroup();
double[] data0 = {60, 50, 190, 240, 110}; //grey values
barlayer.addDataSet(data0,0xdbdbdb);

c.xAxis().setLabels(labels);
String chart1URL = c.makeSession(request, "chart1");
String imageMap1 = c.getHTMLImageMap("", "", "");
%>
<html>
<body>
<img src="getchart.jsp?<%=chart1URL%>" usemap="#map1" border="0">
<map name="map1"><%=imageMap1%></map>
</body>
</html>
[/code]


With "addBarLayer2()" & "addDataSet()" I've only found one color for one DataGroup.

---
Thanks
Tom
chart.png

  Re: Order / Change Bar-Position
Posted by Peter Kwan on Nov-25-2014 00:12
Hi Tom,

If the grey bars are in front of the multi-color bars, they may hide the multi-color bars. If
this is what you need, you may use two bar layers:

// Add the grey bars first, which will stay in front
BarLayer barlayer2 = c.addBarLayer(data0,0xdbdbdb);

// Add the color bars at the back
BarLayer barlayer = c.addBarLayer3(data, colors);

Hope this can help.

Regards
Peter Kwan

  Re: Order / Change Bar-Position
Posted by Tom on Nov-25-2014 03:16
Hi Peter
Thanks for the quick answer.

Sorry, I meant, the grey bar should be on the left side of the multi-color bar.
I would like to change the bar position (gray <-> multi-color).

---
Regrds
Tom

  Re: Order / Change Bar-Position
Posted by Peter Kwan on Nov-26-2014 01:17
Hi Tom,

Instead of using addBarLayer3, I suggest you use the following method:

//The grey bars
BarLayer layer = c.addBarLayer(data0, 0xdbdbdb);
layer.addDataGroup();


// The multi-color bars
double[] buffer = new double[data.Length];
Arrays.fill(buffer, Chart.NoValue);
for (int i = 0; i < data.length; ++i) {
    buffer[i] = data1[i];
    layer.addDataSet(buffer, colors[i]);
    buffer[i] = Chart.NoValue;
}


Hope this can help.

Regards
Peter Kwan

  Re: Order / Change Bar-Position
Posted by Tom on Nov-26-2014 20:47
Hi Peter

Thank you for your help, it works. :-)
Great support!

---
Regards
Tom