hi
Is it possible to select the colour to plot bars while calling
chartFactory.createVerticalXYBarChart()? or any other chart for that matter?
Is it possible to choose during a run of any dynamic chart?
Thanks
Gaurav Kathotia
Colour Selection
Re: Colour Selection
The bar colors are set on a per series basis using the setSeriesPaint(...) method in the Plot class. You can change these colors at any point after the chart is created.
Regards,
DG.
Regards,
DG.
Re: Colour Selection
thanks DG
But is there is any example or any demo program that shows colour selection or change ? I am getting confused with the java.awt.Paint
interface or how to go about it?
Thanks in advance
Gaurav Kathotia
But is there is any example or any demo program that shows colour selection or change ? I am getting confused with the java.awt.Paint
interface or how to go about it?
Thanks in advance
Gaurav Kathotia
Re: Colour Selection
Two steps.
First, I've extended AbstractSeriesDataset.
----------------------
public class myXYData extends AbstractSeriesDataset implements IntervalXYDataset
----------------------
In this class, I've included a method to get Paint for the current (int series, int item). You can return whatever Paint you want from here.
------------------------
private static Paint[] seriesPaint = new Paint[] {Color.red, Color.lightGray, Color.green};
....
public Paint getItemPaint(int series, int item)
{
double d = change[item].doubleValue();
if (d < 0)
return this.seriesPaint[0];
else if (d == 0)
return this.seriesPaint[1];
else
return this.seriesPaint[2];
}
-------------------------------
Step 2:
I extended the VerticalXYBarRendered and overriden drawItem method.
...................
if (data instanceof myXYData)
seriesPaint = ((myXYData)data).getItemPaint(series, item);
else
seriesPaint = plot.getSeriesPaint(series);
....................
Thats it !!!!
Mudit
First, I've extended AbstractSeriesDataset.
----------------------
public class myXYData extends AbstractSeriesDataset implements IntervalXYDataset
----------------------
In this class, I've included a method to get Paint for the current (int series, int item). You can return whatever Paint you want from here.
------------------------
private static Paint[] seriesPaint = new Paint[] {Color.red, Color.lightGray, Color.green};
....
public Paint getItemPaint(int series, int item)
{
double d = change[item].doubleValue();
if (d < 0)
return this.seriesPaint[0];
else if (d == 0)
return this.seriesPaint[1];
else
return this.seriesPaint[2];
}
-------------------------------
Step 2:
I extended the VerticalXYBarRendered and overriden drawItem method.
...................
if (data instanceof myXYData)
seriesPaint = ((myXYData)data).getItemPaint(series, item);
else
seriesPaint = plot.getSeriesPaint(series);
....................
Thats it !!!!
Mudit