A discussion forum for JFreeChart (a 2D chart library for the Java platform).
-
jesusmgmarin
- Posts: 13
- Joined: Thu Apr 20, 2006 2:24 pm
- Location: Spain
-
Contact:
Post
by jesusmgmarin » Thu Jul 06, 2006 10:52 am
Hello, I have a XYBarChart but it has severals values, and the bars are superposed because they are a little wide. I want to know if there is some method to modify the width of the bars. The code I have is:
Code: Select all
public JFreeChart BarsChart(String vInDep, String vDep){
final XYSeries series = new XYSeries();
/* I load the chart */
for (int i=0; i<arrayVars.length; i++){
float x= Float.parseFloat(arrayVars[i][0]);
float y= Float.parseFloat(arrayVars[i][1]);
series.add(x,y);
}
final XYSeriesCollection ColeccionDatos = new XYSeriesCollection(series);
final JFreeChart chart = ChartFactory.createXYBarChart(
"Chart Barras "+vDep+" vs "+vInDep, //Tittle
vInDep, //Legend X Axis
false,
vDep, //Legend Y Axis
ColeccionDatos, //Dataset
PlotOrientation.HORIZONTAL, //Orientation
true, //Flag legend
true, //Flag tooltip
false //Flag URLs
);
/* **************************************** */
/* I invest the Domain to create the "graph in depth" */
XYPlot plot = (XYPlot) chart.getPlot();
NumberAxis rangeAxis = (NumberAxis) plot.getDomainAxis();
rangeAxis.setInverted(true);
/* **************************************** */
return chart;
}
Thanks very much
-
jesusmgmarin
- Posts: 13
- Joined: Thu Apr 20, 2006 2:24 pm
- Location: Spain
-
Contact:
Post
by jesusmgmarin » Thu Jul 06, 2006 5:41 pm
I have already solved this, I had to do this after ...
Code: Select all
.....
final JFreeChart chart = ChartFactory.createXYBarChart(
"Chart Barras "+vDep+" vs "+vInDep, //Tittle
vInDep, //Legend X Axis
false,
vDep, //Legend Y Axis
ColeccionDatos, //Dataset
PlotOrientation.HORIZONTAL, //Orientation
true, //Flag legend
true, //Flag tooltip
false //Flag URLs
);
/* **************************************** */
/* I invest the Domain to create the "graph in depth" */
XYPlot plot = (XYPlot) chart.getPlot();
NumberAxis rangeAxis = (NumberAxis) plot.getDomainAxis();
rangeAxis.setInverted(true);
/* **************************************** */
I have post:
Code: Select all
[b]final XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
renderer.setMargin(0.95);[/b]
return chart;