Hi,
Despite the use of the setVerticalLabels(boolean flag) method, the labels which indicate the values of the bars in bar charts remain horizontal.
(the boolean changes normally). What did I do wrong ?
example :
CategoryPlot plot = chart.getCategoryPlot();
plot.setLabelsVisible(true); (OK)
plot.setVerticalLabels(true);
Thanks
pb of orientation of the value labels
Re: pb of orientation of the value labels
Not sure what you did completely, maybe you should check e.g. for
NumberAxis valueAxis = new VerticalNumberAxis(valueAxisLabel);
in the ChartFactory. The example completely shows:
------------------------------------------------------------
public static JFreeChart createStackedVerticalBarChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset data,
boolean legend) {
CategoryAxis categoryAxis = new HorizontalCategoryAxis(categoryAxisLabel);
NumberAxis valueAxis = new VerticalNumberAxis(valueAxisLabel);
CategoryItemRenderer renderer = new StackedVerticalBarRenderer();
Plot plot = new VerticalCategoryPlot(data, categoryAxis, valueAxis, renderer);
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
return chart;
}
------------------------------------------------------------
So you probably should check your code for horizontal and vertical axis with the according labels. Usually, at least here, the label is vertical and the values are horizontal. Setting the direction is not necessary.
NumberAxis valueAxis = new VerticalNumberAxis(valueAxisLabel);
in the ChartFactory. The example completely shows:
------------------------------------------------------------
public static JFreeChart createStackedVerticalBarChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset data,
boolean legend) {
CategoryAxis categoryAxis = new HorizontalCategoryAxis(categoryAxisLabel);
NumberAxis valueAxis = new VerticalNumberAxis(valueAxisLabel);
CategoryItemRenderer renderer = new StackedVerticalBarRenderer();
Plot plot = new VerticalCategoryPlot(data, categoryAxis, valueAxis, renderer);
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
return chart;
}
------------------------------------------------------------
So you probably should check your code for horizontal and vertical axis with the according labels. Usually, at least here, the label is vertical and the values are horizontal. Setting the direction is not necessary.
Re: pb of orientation of the value labels
I use the ChartFactory to create my vertical bar chart. I thought I would'nt have to deal with the horizontal and vertical axis. What I want to put vertical direction is the labels which appear on top of each bar with the value of the bar inside.
here is my code :
double[][] data = new double[][] {
{ 111.0, 444.0, 377.0, 555.0, 554.0, 777.0, 477.0, 148.0 },
{ 555.0, 443.0, 666.0, 888.0, 444.0, 455.0, 222.0, 111.0 },
{ 444.0, 344.0, 244.0, 344.0, 644.0, 344.0, 444.0, 344.0 }
};
DefaultCategoryDataset dataset = new DefaultCategoryDataset(data);
JFreeChart chart = ChartFactory.createVerticalBarChart
("Title", "Category", "Value", dataset, true );
CategoryPlot plot = chart.getCategoryPlot();
// label data points with values...
plot.setLabelsVisible(true); //OK
plot.setVerticalLabels(true); //THIS LINE SEEMS NOT TO WORK !
System.out.println("isVertical? :"+plot.getVerticalLabels());//the boolean changes normally
here is my code :
double[][] data = new double[][] {
{ 111.0, 444.0, 377.0, 555.0, 554.0, 777.0, 477.0, 148.0 },
{ 555.0, 443.0, 666.0, 888.0, 444.0, 455.0, 222.0, 111.0 },
{ 444.0, 344.0, 244.0, 344.0, 644.0, 344.0, 444.0, 344.0 }
};
DefaultCategoryDataset dataset = new DefaultCategoryDataset(data);
JFreeChart chart = ChartFactory.createVerticalBarChart
("Title", "Category", "Value", dataset, true );
CategoryPlot plot = chart.getCategoryPlot();
// label data points with values...
plot.setLabelsVisible(true); //OK
plot.setVerticalLabels(true); //THIS LINE SEEMS NOT TO WORK !
System.out.println("isVertical? :"+plot.getVerticalLabels());//the boolean changes normally