|
How to set the border size of a bar |
Posted by walwyss on May-12-2011 10:45 |
|
Hi,
I encoutered a problem while using bar chart. I created a bar layer with several bars. I set the edge color but made the fill color transparent. The problem is that I couldn't find a way to set the border size. Could someone help me? Thanks.
The following is the code:
double[] data=new double[]{10, 20, 30, 40, 50};
BarLayer barLayer = xyChart.addBarLayer(data, Chart.Transparent);
barLayer.setBorderColor(0x0000FF, Chart.softLighting(Chart.Left));
// How to set border size?
walwyss |
Re: How to set the border size of a bar |
Posted by Peter Kwan on May-13-2011 01:48 |
|
Hi walwyss,
By border size, I assume you are referring to the line width of the bar border.
There is only a 3D border width in the ChartDirector API, which configures the width of the 3D raised or depressed border effect. It configurable in "Layer.setBorderColor". If softLighting is used, you can supply the 3D border width as the second parameter to softLighting.
However, the above is not the same as the border of the bar. Unluckily, in ChartDirector, the border width of the bar is not configurable.
For 2D transparent bars, the only method I can think of is to create multiple bar layers using the same data, so that they overlap. The bars in a layer should be configured as 2 pixels wider than the previous layer. (The bar width is configuable using BarLayer.setBarWidth.) In this way, you can create bars with thicker left and right borders. Only the first bar layer needs to have the "softLighting" effect.
For the top border, you can create a box-whisker layer with just the "middle line", using the same data as the bar layers, and use a thick line width. The "middle line" will become the top border of the bar.
Regards
Peter Kwan |
Re: How to set the border size of a bar |
Posted by walwyss on May-13-2011 09:49 |
|
Hi Peter,
Thanks for your explanation. But I have another question.
Currently I want to create a two-bar chart overlapping: a set of hollow bars to indicate the capacity and a set of solid bars as the actual value. The bars for the actualValue are solid and the bars for the capacity are hollow. A same set of colors is used as fill color for the former and as edge color for the latter. How to implement it? Thanks in advance.
The sample code is as follows:
double[] actualValue= new double[]{10, 20, 30, 40, 50};
double[] capacity = new double[]{100, 100, 100, 100, 100};
int[] barColor = new int[] {&0000FF, &00FF00, &FF0000, &00FFFFF, &FFFF00};
// how to create a overlapping two-bar chart described above?????
Walwyss |
Re: How to set the border size of a bar |
Posted by Peter Kwan on May-14-2011 02:57 |
|
Hi walwyss,
I assume you would like to create a "multi-color" bar chart (each bar has a different color). In this case, you may try (in C#):
BarLayer layer0 = c.addBarLayer3(actualValue, barColor);
for (int i = 0; i < actualValue.Length; ++i) {
double[] capacity = {Chart.NoValue. Chart.NoValue, Chart.NoValue, Chart.NoValue, Chart.NoValue};
capacity[i] = 100;
c.addBarLayer(capacity, Chart.Transparent).setBorderColor(barColor[i]);
}
Hope this can help.
Regards
Peter Kwan |
Re: How to set the border size of a bar |
Posted by walwyss on May-14-2011 08:55 |
|
Hi Peter,
Your code works in 2-D perfectly. But I also want it in i 3-D mode. Is it possible?
walwyss |
Re: How to set the border size of a bar |
Posted by Peter Kwan on May-14-2011 18:04 |
|
Hi walwyss,
May be you can try:
BarLayer layer = c.addBarLayer2(Chart.Overlay, 5);
for (int i = 0; actualValue.Length; ++i) {
double[] buffer = {Chart.NoValue. Chart.NoValue, Chart.NoValue, Chart.NoValue, Chart.NoValue};
buffer[i] = actualValue[i];
layer.addDataSet(buffer).setDataColor(barColor[i], barColor[i]);
buffer[i] = 100;
layer.addDataSet(buffer).setDataColor(Chart.Transparent, barColor[i]);
}
Hope this can help.
Regards
Peter Kwan |
Re: How to set the border size of a bar |
Posted by walwyss on May-16-2011 08:33 |
|
Hi Peter,
It is what I wanted. Thanks a lot.
walwyss |
|