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

Message ListMessage List     Post MessagePost Message

  horizontal gradient
Posted by ron on Oct-26-2011 07:00
Hi there,

does anyone know how to make horizontal gradient on vertical bar? i'm failing on calculating the start and end position of the xaxis

cheers
R

  Re: horizontal gradient
Posted by Peter Kwan on Oct-26-2011 23:52
Hi Ron,

For your case, there are two methods, depending on exactly what type of gradients you would like to use.

(a) ChartDirector has built-in support for several different types of bars shading, one of them is called "soft lighting", and the effect is like the first chart in our chart gallery page

http://www.advsofteng.com/gallery_bar2.html.

In the example in the gallery page, you can see the bars are vertical, but the gradient is horizontal. However, the gradient is limited to making the original color lighting and darker, such as from light blue to dark blue. You cannot have an arbitrary gradient such as from red to green.

(b) If you would like to define your own gradient, you can use linearGradientColor. The following is an example (in C++) that shows a "Multi-Color Bar Chart", in which each bar is having a different custom horizontal gradient.

int x0 = c->getPlotArea()->getLeftX();
int xWidth = c->getPlotArea()->getWidth();

//each bar has a different and custom gradient color from startColor[i] to endColor[i]
std::vector<int> colors;
for (int i = 0; i < noOfBars; ++i)
     colors.push_back(c->linearGradientColor(x0 + i * xWidth / noOfBars, 0, x0 + (i + 1) * xWidth / noOfBars, 0, startColor[i], endColor[i]);

//add the bar layer using the colors
BarLayer *layer = c->addBarLayer(DoubleArray(data, noOfBars), IntArray(&(colors[0]), noOfBars));
layer->setBorderColor(Chart::SameAsMainColor);

If you need to translate the code to another programming language, please let me know.

Regards
Peter Kwan

  Re: horizontal gradient
Posted by Ron on Oct-27-2011 06:08
Attachments:
Hi Pete,

thanks for your reply.. your sample worked okay on vertical bar but not on horizontal bar.

this is the change I made for horizontal bar:

int x0 = c->getPlotArea()->getTopY();
int xWidth = c->getPlotArea()->getHeight();

//each bar has a different and custom gradient color from startColor[i] to endColor[i]
std::vector<int> colors;
for (int i = 0; i < noOfBars; ++i)
     colors.push_back(c->linearGradientColor(0, x0 + i * xWidth / noOfBars, 0, x0 + (i + 1) * xWidth / noOfBars, startColor[i], endColor[i]);


please see attachment for image.. can you please help?

thanks
R
gradientnotokay.png

  Re: horizontal gradient
Posted by John on Oct-27-2011 13:05
Please refer to this thread which contains more details on the problem we're having:

http://www.chartdir.com/forum/download_thread.php?site=chartdir&bn=chartdir_support&thread=1084981568#N1319670439

Thanks, JC

  Re: horizontal gradient
Posted by Peter Kwan on Oct-28-2011 03:05
Hi Ron/John,

Please refer to my response at:

http://www.chartdir.com/forum/download_thread.php?site=chartdir&bn=chartdir_support&thread=1084981568#N1319742229

Regards
Peter Kwan