Hi,
Does anyone know how I can get something like this photo?
I want to get the text horizontally on the bar.
I tried with text annotation but I have not gotten...
Thanks.
How can i get something like this annotation at barchart?
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: How can i get something like this annotation at barchart
Do tehse values represent the data value of the respective bars?
Re: How can i get something like this annotation at barchart
paradoxoff wrote:Do tehse values represent the data value of the respective bars?
Yes. Is the value of the bar. But could be a string anyone, no matter.
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: How can i get something like this annotation at barchart
Well, if the numbers indeed represent the data value, then you could just have a look at the item labelling capability of JFreeChart.
Use this code as a starter:
Use this code as a starter:
Code: Select all
public class BarChart extends ApplicationFrame {
public BarChart(String title) {
super(title);
final CategoryDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 350));
setContentPane(chartPanel);
}
private CategoryDataset createDataset() {
double[][] data = new double[][]{
{10,8},
{8,4},
{12,6},
{6,9},
{9,12}};
return DatasetUtilities.createCategoryDataset(
"Row ", "Column ", data);
}
private JFreeChart createChart(final CategoryDataset dataset) {
BarRenderer br = new BarRenderer();
br.setBaseItemLabelsVisible(true);
br.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
br.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, Math.PI/2.0));
CategoryPlot cp = new CategoryPlot(dataset, new CategoryAxis("x"), new NumberAxis("x"), br);
return new JFreeChart(cp);
}
public static void main(final String[] args) {
final BarChart demo
= new BarChart("Bar Chart");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
}
Re: How can i get something like this annotation at barchart
It works, thank you very much !