Changing the color
Changing the color
Hi,
I am not able to understand how to use setCategoriesPaint(.. ). Could someone give me an example.
Thanks,
--Narasimha
I am not able to understand how to use setCategoriesPaint(.. ). Could someone give me an example.
Thanks,
--Narasimha
Re: Changing the color
Hello,
Here is an example using an instance of the class VerticalBarRenderer, that we will call myVerticalBarRenderer.
// First, define Your colors
// You can use predefined colors (Color.blue), or create Your owns with
// (r,v,b) values
Paint[] seriesPaint = {
Color.red,
new Color(255, 154, 0),
Color.blue,
Color.darkGray,
Color.magenta,
new Color(156, 207, 0),
new Color(0, 207, 255)
};
// then, assign them to Your renderer
myVerticalBarRenderer.setCategoriesPaint(seriesPaint);
Regards,
Arnaud
Here is an example using an instance of the class VerticalBarRenderer, that we will call myVerticalBarRenderer.
// First, define Your colors
// You can use predefined colors (Color.blue), or create Your owns with
// (r,v,b) values
Paint[] seriesPaint = {
Color.red,
new Color(255, 154, 0),
Color.blue,
Color.darkGray,
Color.magenta,
new Color(156, 207, 0),
new Color(0, 207, 255)
};
// then, assign them to Your renderer
myVerticalBarRenderer.setCategoriesPaint(seriesPaint);
Regards,
Arnaud
Re: Changing the color
Hi
Thanks for your reply, but i dont find the setCategoriesPaint method in VerticalBarRenderer. Is there anything else i am missing here.
Thanks,
-Narasimha
Thanks for your reply, but i dont find the setCategoriesPaint method in VerticalBarRenderer. Is there anything else i am missing here.
Thanks,
-Narasimha
Re: Changing the color
Hello,
The class VerticalBarRenderer inherits from the class BarRenderer which itself inherits from the class AbstractCategoryItemRenderer in which the method setCategoriesPaint() is defined...
Have a look on the javadoc, http://www.object-refinery.com/jfreecha ... derer.html.
Regards,
Arnaud
The class VerticalBarRenderer inherits from the class BarRenderer which itself inherits from the class AbstractCategoryItemRenderer in which the method setCategoriesPaint() is defined...
Have a look on the javadoc, http://www.object-refinery.com/jfreecha ... derer.html.
Regards,
Arnaud
Re: Changing the color
Hi,
Thanks for your reply, but i am not able to set the color of the categories. Below is the code in which i have set the categories paint. Please let me know if its correct
chart = ChartFactory.createVerticalBarChart(title,
xtitle,
ytitle,
categoryData, true);
VerticalBarRenderer myVertical = new VerticalBarRenderer();
myVertical.setCategoriesPaint(paint);
chart.setBackgroundPaint(new GradientPaint(0, 0, getColor(color),
1000, 0, getColor(finalGradColor)));
chart.setBackgroundPaint(getColor(color));
plot = chart.getCategoryPlot();
axis = (HorizontalCategoryAxis) plot.getDomainAxis();
axis.setVerticalCategoryLabels(true);
return chart;
Thanks for your reply, but i am not able to set the color of the categories. Below is the code in which i have set the categories paint. Please let me know if its correct
chart = ChartFactory.createVerticalBarChart(title,
xtitle,
ytitle,
categoryData, true);
VerticalBarRenderer myVertical = new VerticalBarRenderer();
myVertical.setCategoriesPaint(paint);
chart.setBackgroundPaint(new GradientPaint(0, 0, getColor(color),
1000, 0, getColor(finalGradColor)));
chart.setBackgroundPaint(getColor(color));
plot = chart.getCategoryPlot();
axis = (HorizontalCategoryAxis) plot.getDomainAxis();
axis.setVerticalCategoryLabels(true);
return chart;
Re: Changing the color
Hello,
When You write :
myVertical.setCategoriesPaint(paint);
You must define first what paint is.
Try this :
Paint[] seriesPaint = {
Color.red,
new Color(255, 154, 0),
Color.blue,
Color.darkGray,
Color.magenta,
new Color(156, 207, 0),
new Color(0, 207, 255)
};
chart = ChartFactory.createVerticalBarChart(title,
xtitle,
ytitle,
categoryData, true);
VerticalBarRenderer myVertical = new VerticalBarRenderer();
myVertical.setCategoriesPaint(seriesPaint);
chart.setBackgroundPaint(new GradientPaint(0, 0, getColor(color),
1000, 0, getColor(finalGradColor)));
chart.setBackgroundPaint(getColor(color));
plot = chart.getCategoryPlot();
axis = (HorizontalCategoryAxis) plot.getDomainAxis();
axis.setVerticalCategoryLabels(true);
return chart;
Regards,
Arnaud
When You write :
myVertical.setCategoriesPaint(paint);
You must define first what paint is.
Try this :
Paint[] seriesPaint = {
Color.red,
new Color(255, 154, 0),
Color.blue,
Color.darkGray,
Color.magenta,
new Color(156, 207, 0),
new Color(0, 207, 255)
};
chart = ChartFactory.createVerticalBarChart(title,
xtitle,
ytitle,
categoryData, true);
VerticalBarRenderer myVertical = new VerticalBarRenderer();
myVertical.setCategoriesPaint(seriesPaint);
chart.setBackgroundPaint(new GradientPaint(0, 0, getColor(color),
1000, 0, getColor(finalGradColor)));
chart.setBackgroundPaint(getColor(color));
plot = chart.getCategoryPlot();
axis = (HorizontalCategoryAxis) plot.getDomainAxis();
axis.setVerticalCategoryLabels(true);
return chart;
Regards,
Arnaud
Re: Changing the color
Hi,
I am sorry i did not give you the exact code. I have already defined above paint. But if you see the ChartFactory there is a call to the renderer. I am wondering if any change needs to be then there.
Please let me know.
Thanks,
--Narasimha
I am sorry i did not give you the exact code. I have already defined above paint. But if you see the ChartFactory there is a call to the renderer. I am wondering if any change needs to be then there.
Please let me know.
Thanks,
--Narasimha
Re: Changing the color
Hello,
I did not look properly at Your code, so my response was false...
Instead of :
VerticalBarRenderer myVertical = new VerticalBarRenderer();
myVertical.setCategoriesPaint(paint);
You should do something like :
((AbstractCategoryItemRenderer) chart.getCategoryPlot().getRenderer()).setCategoriesPaint(paint);
The error is that You didn't get the renderer associated with Your chart instance, but created a new one without using it to update Your chart.
Regards,
Arnaud
I did not look properly at Your code, so my response was false...
Instead of :
VerticalBarRenderer myVertical = new VerticalBarRenderer();
myVertical.setCategoriesPaint(paint);
You should do something like :
((AbstractCategoryItemRenderer) chart.getCategoryPlot().getRenderer()).setCategoriesPaint(paint);
The error is that You didn't get the renderer associated with Your chart instance, but created a new one without using it to update Your chart.
Regards,
Arnaud
Re: Changing the color
Hi,
Thanks for ypur help but i dont think its working. I have put some more code. Please let me know if i am correctly.
thanks,
--Narasimha
public JFreeChart createChart(int type,Vector respondents, String survey,String title,String xtitle,String ytitle,String[] respArr){
CategoryDataset categoryData = createCategoryDataset(respondents,respArr);
int color=0;
int finalGradColor=1;
Paint[] paint = {Color.red,new Color(255, 154, 0),Color.blue,Color.darkGray,Color.magenta,
new Color(156, 207, 0),new Color(0, 207, 255)};
CategoryPlot plot;
HorizontalCategoryAxis axis;
JFreeChart chart;
try {
switch (type) {
case 1:
chart = ChartFactory.createVerticalBarChart3D(title, xtitle,ytitle,categoryData,
true);
((AbstractCategoryItemRenderer) chart.getCategoryPlot().getRenderer()).setCategoriesPaint(paint);
return chart;
Thanks for ypur help but i dont think its working. I have put some more code. Please let me know if i am correctly.
thanks,
--Narasimha
public JFreeChart createChart(int type,Vector respondents, String survey,String title,String xtitle,String ytitle,String[] respArr){
CategoryDataset categoryData = createCategoryDataset(respondents,respArr);
int color=0;
int finalGradColor=1;
Paint[] paint = {Color.red,new Color(255, 154, 0),Color.blue,Color.darkGray,Color.magenta,
new Color(156, 207, 0),new Color(0, 207, 255)};
CategoryPlot plot;
HorizontalCategoryAxis axis;
JFreeChart chart;
try {
switch (type) {
case 1:
chart = ChartFactory.createVerticalBarChart3D(title, xtitle,ytitle,categoryData,
true);
((AbstractCategoryItemRenderer) chart.getCategoryPlot().getRenderer()).setCategoriesPaint(paint);
return chart;
Re: Changing the color
I was having the same problem and this thread was very helpful,
However rather than:
((AbstractCategoryItemRenderer) chart.getCategoryPlot().getRenderer()).setCategoriesPaint(paint);
Try:
chart.getCategoryPlot().setCategoriesPaint(paint);
This worked for me.
Peter FitzPatrick
However rather than:
((AbstractCategoryItemRenderer) chart.getCategoryPlot().getRenderer()).setCategoriesPaint(paint);
Try:
chart.getCategoryPlot().setCategoriesPaint(paint);
This worked for me.
Peter FitzPatrick
Re: Changing the color
Hi,
Thanks for your response, but it doesnt work either. The interface CategoryItemRenderer doesnt define setCategoriesPaint. Could you please give me a sample code.
Thanks in advance,
--Narasimha
Thanks for your response, but it doesnt work either. The interface CategoryItemRenderer doesnt define setCategoriesPaint. Could you please give me a sample code.
Thanks in advance,
--Narasimha
Re: Changing the color
Narasimha
The was a mistake in my reply, sorry about that it should be:-
chart.getCategoryPlot().setSeriesPaint(paint);
Not
chart.getCategoryPlot().setCategoriesPaint(paint);
Try that instead, it should work.
Peter
The was a mistake in my reply, sorry about that it should be:-
chart.getCategoryPlot().setSeriesPaint(paint);
Not
chart.getCategoryPlot().setCategoriesPaint(paint);
Try that instead, it should work.
Peter
Re: Changing the color
Hello again,
Well... got mixed up with versions 0.9.4 and version 0.9.5... my responses dealt with version 0.9.4, and code I had experimented. As I'm currently upgrading to 0.9.5, I understand Your troubles !
Heres is what I learn, by carefully reading the javadoc - version 0.9.5 :
1) Class AbstractCategoryItemRenderer, setCategoriesPaint(java.awt.Paint[] paint) :
"Sets the paint to be used for categories under special circumstances.
This attribute is provided for the situation where there is just one series, and you want each category item to be plotted using a different color (ordinarily, the series color is used for all the items in the series). "
2) Class AbstractRenderer, setSeriesPaint(int dataset, int series, java.awt.Paint paint) :
"Sets the paint used for a series."
--> therefore, If You have multiple series and one category, You need to use the setSeriesPaint instead of the setCategoriesPaint method. I think it is a bit confusing as version 0.9.4 used the setCategoriesPaint for that case... but we now have the power to use different colors with one series and multiple categories ! So, the code You need may finally be something like this :
renderer.setSeriesPaint(0,new Color(206, 255, 206));
renderer.setSeriesPaint(1,new Color(156, 207, 0));
renderer.setSeriesPaint(2,new Color(255, 207, 156));
renderer.setSeriesPaint(3,new Color(255, 154, 0));
renderer.setSeriesPaint(4,new Color(206, 255, 255));
renderer.setSeriesPaint(5,new Color(156, 206, 255));
renderer.setSeriesPaint(6,new Color(0, 207, 255));
I think it may be interesting to have a setSeriesPaint(int dataset, int series, java.awt.Paint[] paint)... I'll have a look later on that.
Hope that time it will really help You make Your code work !
Regards,
Arnaud
Well... got mixed up with versions 0.9.4 and version 0.9.5... my responses dealt with version 0.9.4, and code I had experimented. As I'm currently upgrading to 0.9.5, I understand Your troubles !
Heres is what I learn, by carefully reading the javadoc - version 0.9.5 :
1) Class AbstractCategoryItemRenderer, setCategoriesPaint(java.awt.Paint[] paint) :
"Sets the paint to be used for categories under special circumstances.
This attribute is provided for the situation where there is just one series, and you want each category item to be plotted using a different color (ordinarily, the series color is used for all the items in the series). "
2) Class AbstractRenderer, setSeriesPaint(int dataset, int series, java.awt.Paint paint) :
"Sets the paint used for a series."
--> therefore, If You have multiple series and one category, You need to use the setSeriesPaint instead of the setCategoriesPaint method. I think it is a bit confusing as version 0.9.4 used the setCategoriesPaint for that case... but we now have the power to use different colors with one series and multiple categories ! So, the code You need may finally be something like this :
renderer.setSeriesPaint(0,new Color(206, 255, 206));
renderer.setSeriesPaint(1,new Color(156, 207, 0));
renderer.setSeriesPaint(2,new Color(255, 207, 156));
renderer.setSeriesPaint(3,new Color(255, 154, 0));
renderer.setSeriesPaint(4,new Color(206, 255, 255));
renderer.setSeriesPaint(5,new Color(156, 206, 255));
renderer.setSeriesPaint(6,new Color(0, 207, 255));
I think it may be interesting to have a setSeriesPaint(int dataset, int series, java.awt.Paint[] paint)... I'll have a look later on that.
Hope that time it will really help You make Your code work !
Regards,
Arnaud
Re: Changing the color
Hi Arnaud,
What I'm hoping is that you can now override the getItemPaint(...) method in any renderer to use multiple colors within one series. I say "hoping" because I've set the code up so that it should be possible, but I haven't tested it so I could have messed something up.
In my own charts, I use a single color for each series so that it is easy to identify the series...I'm not sure of the purpose of using multiple colors within a series.
Regards,
Dave Gilbert
What I'm hoping is that you can now override the getItemPaint(...) method in any renderer to use multiple colors within one series. I say "hoping" because I've set the code up so that it should be possible, but I haven't tested it so I could have messed something up.
In my own charts, I use a single color for each series so that it is easy to identify the series...I'm not sure of the purpose of using multiple colors within a series.
Regards,
Dave Gilbert