|
horizontal gradient on vertical BarLayer2(Chart.Overlay) |
Posted by Stemberger on Feb-11-2013 22:50 |
|
Hello,
I'm trying to put an horizontal gradient like to this post: http://www.chartdir.com/forum/download_thread.php?site=chartdir&bn=chartdir_support&thread=1084981568
but it doesn't work. I always got a shift on the startx coordinate of the first color...
layer.setBarGap(Chart.TouchBar,Chart.TouchBar);
int plotAreaLeft = c.getPlotArea().getLeftX();
int plotAreaWidth = c.getPlotArea().getWidth();
double barLeft = plotAreaLeft + ((plotAreaWidth / xdates.length ) * i);
double barRight = barLeft + (plotAreaWidth / xdates.length );
double[] temp = new double[data0.length];
for (int i = 0; i < data0.length; ++i) {
double barLeft = plotAreaLeft + ((plotAreaWidth / data0.length ) * i);
double barRight = barLeft + 1 + (plotAreaWidth / data0.length );
temp[i] = data0[i];
layer.addDataSet(temp, c.linearGradientColor((int) barLeft, 0, (int) barRight, 0, couleurDeb, couleurFin), i == 0 ? legend0 : "");
temp[i] = 0;
}
Thanks for your help
SL |
Re: horizontal gradient on vertical BarLayer2(Chart.Overlay) |
Posted by Peter Kwan on Feb-12-2013 01:02 |
|
Hi Stemberger,
From your code, I assume you are drawing a vertical bar chart, with the gradient from left to right.
I think you barLeft should be:
double barLeft = plotAreaLeft + ((plotAreaWidth / (double)xdates.length ) * i);
In your original code, you are using integer division (plotAreaWidth / data0.length), which will round down to an integer. This introduces up to 1 pixel of error. After multiplying by i, it can become many pixels of error. If you use floating point division instead, the error will be negligible.
Hope this can help.
Regards
Peter Kwan |
Re: horizontal gradient on vertical BarLayer2(Chart.Overlay) |
Posted by Stemberger on Feb-12-2013 23:57 |
|
Hi,
thank you very much, it works now.
SL |
|