|
Positive Negative Bars with more than 2 colors |
Posted by Dominique Vettese on Apr-05-2011 17:47 |
|
Hello,
On my positive negative bar chart, i would like to use more than just two color: 1 for positive bar and 1 for negative bar.
See barchart sample un attachment:
-> the first bar have always the same color (the payed amount)
-> the intermediaries bar a green color (the interests)
-> the last bar 2 miwed colors: blue for the received amount and green for the interest
I tried the positive negative bar code like this:
//Donn?es de la barre des Y
double[] data = dataYaxis;
//Donn?es de la barre des X
string[] labels = new string[dataXaxis.Length];
for(int i=0;i<dataXaxis.Length;i++)
{
labels[i] = Convert.ToString(i);
}
//Create a XYChart object of size 380 x 250 pixels
ChartDirector.XYChart c = new ChartDirector.XYChart(500, 420);
//Set the plotarea at (45, 30) and of size 530 x 240 pixels
c.setPlotArea(50, 30, 400, 280, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC).setBackground(0xffffff, 0xffffff, 0xCCCCCC);
//Add a title to the chart using Arial Bold Italic font
c.addTitle(ddlProduct.SelectedItem.Text, "Arial Bold", 10, 0x006699);
//Couleur de la barre Y
c.yAxis().setColors(0xCCCCCC);
c.yAxis().setLabelStyle("verdana.ttf", 7, 0x999999);
//Add a title to the y axis
c.yAxis().setTitle(contentDictionary["yAxisTitle"], "Arial Bold", 10, 0x000000);
//Couleur de la barre X
c.xAxis().setColors(0xCCCCCC);
c.xAxis().setLabelStyle("verdana.ttf", 8, 0x999999);
c.xAxis().setLabels(labels);
//Add a title to the x axis
c.xAxis().setTitle(contentDictionary["xAxisTitle"], "Arial Bold", 10, 0x000000);
//Add a bar layer to the chart
BarLayer layer = c.addBarLayer2();
layer.setBorderColor(Chart.Transparent);
//Add a data set to the bar using a y zone color.
//The color is configured to be //orange (0xC2C2C2) below zero, and blue (0x006599) above zero.
layer.addDataSet(data, layer.yZoneColor(0, 0xC2C2C2, 0x006599));
//---Outputchart
webChartResult.Image = c.makeWebImage(Chart.GIF);
but I don't find the way to obtain more than 2 colors on this type of chart.
Thanks for your help,
Dominique Vettese
|
Re: Positive Negative Bars with more than 2 colors |
Posted by Dominique Vettese on Apr-05-2011 18:28 |
|
Hi,
I modified my code to include an array color an a call to addBarLayer3 method instead of addDataSet method:
//bars chart colors
int[] colors;
colors = new int[dataXaxis.Length];
for (int j = 0; j < dataXaxis.Length; j++)
{
if (j == 0)
{colors[j] = 0xC2C2C2;}
else if (j == (dataXaxis.Length - 1))
{colors[j] = 0x006599;}
else
{colors[j] = 0xCCCC33;}
}
....
c.addBarLayer3(data, colors);
see result in attachment.
But I always block to display to mixed color in the last bar on the chart.
Somes ideas?
Thanks,
Dominique Vettese
|
Re: Positive Negative Bars with more than 2 colors |
Posted by Peter Kwan on Apr-06-2011 02:10 |
|
Hi Dominique,
The chart you need can be created as a stacked bar chart. For example:
double[] paid = { -1000, 0, 0, 0, 0, 0 };
double[] interest = { 0, 10, 20, 14, 6, 10 };
double[] received = { 0, 0, 0, 0, 0, 1000 };
BarLayer layer = c.addBarLayer(Chart.Stack);
layer.addDataSet(paid, 0xC2C2C2, "Paid");
layer.addDataSet(received, 0xCCCC33, "Received");
layer.addDataSet(interest, 0x006599, "Interest");
Hope this can help.
Regards
Peter Kwan |
|