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

Message ListMessage List     Post MessagePost Message

  Create Barchart with specific gradients
Posted by Mats H?gglund on Apr-09-2015 15:10
Attachments:
Hi and thanks for a great product!

We would like to create a new gradient effect on our barcharts.
The gradient goes from one specific color to another. For instance: #F14747 - #CA0202.

Is this possible? Cheers, Mats


This is our current barchartcode where we use another effect today.

XYChart barChart2 = new XYChart(450, 350);
barChart2.setPlotArea(70, 65, 300, 230, -1, -1, Chart.Transparent, 0xc0c0c0);
barChart2.setBackground(0xf5f5f5);
barChart2.xAxis().setColors(0xa1a0a0);
barChart2.yAxis().setColors(0xa1a0a0);
Collections.reverse(mySampleValues);
Collections.reverse(mySampleColors);
Collections.reverse(myBarLabels);
BarLayer layer = barChart2.addBarLayer3(RAMUtil.toDoubleArray(mySampleValues),
RAMUtil.toIntArray(mySampleColors));
barChart2.xAxis().setLabels(RAMUtil.toStringArray(myBarLabels));
barChart2.xAxis().setColors(0xa1a0a0);
barChart2.yAxis().setColors(0xa1a0a0);
layer.setDataLabelStyle("Trebuchet_MS.ttf, bold",8,0xffffff);
layer.setBarGap(0.06);
layer.setBorderColor(Chart.Transparent, Chart.softLighting(Chart.Left));
barChart2.swapXY();
barChart2.yAxis().setLabelStyle("Trebuchet_MS.ttf, bold", 8,0xa1a0a0);
barChart2.xAxis().setLabelStyle("Trebuchet_MS.ttf, bold", 8,0xa1a0a0);
gradients examples.png
current panorama.png

  Re: Create Barchart with specific gradients
Posted by Peter Kwan on Apr-11-2015 01:41
Hi Mats,

The Chart.barLighting allows you to specify two brightness parameters for the brightness
at the two end points of the bar. For example, you can set the bar color as 0xff0000 (
saturated red), and set the brightness to be from 0.7 to 1.5. In this case, one of the end
points of the bar will be darker red, and the other side will be brighter red.

Each layer can only have one set of brightness parameters, which means the same
parameters will apply to all bars in the layer, no matter what the bar colors are. Also, this
does not allow for two colors are related by "brightness". For example, you cannot set
the bar color to vary from green to red, or from two different types of red that are not
related by brightness only. (If the end point colors are picked by an artist, rather than by
using some mathematical formula, it is likely the colors are not related by brightness
only.)

To configure each bar to have a different gradient of different colors, you would need to
do something like the followings:

//use multi-color bar layer, but no need to specify the colors here
BarLayer layer = barChart2.addBarLayer3(RAMUtil.toDoubleArray(mySampleValues));

.... create chart as usual .....

//Auto-scale the axis, after that we can know the exact bar positions
c.layoutAxes();

for (int i = 0; i < mySampleValues.Length; ++i)
{
    // The gradient for the bar at index i
    int myBarColor = c.linearGradientColor(c.getPlotArea().getLeftX(), 0,
        c.getYCoor(mySampleValues[i]), 0, startColor[i], endColor[i]);
    layer.getDataSet(i).setDataColor(myBarColor);
}

Hope this can help.

Regards
Peter Kwan

  Re: Create Barchart with specific gradients
Posted by Mats H?gglund on Apr-15-2015 21:09
Thank you very much, it worked!
Awesome support!

Thanks, Mats