0
how to create a BarChart from jtable date by JfreeChart in java?
I have a jtable with 2 column(first is name and second is age), how can create a barchar?
1 Réponse
0
//this is my way and its very good.
DefaultCategoryDataset data = new DefaultCategoryDataset();
DefaultTableModel model = (DefaultTableModel) tableMablagh.getModel();
int i = 0;
for (i = 0; i < model.getRowCount(); i++) {
String name = model.getValueAt(i, 0).toString();
Double cost = Double.valueOf(model.getValueAt(i , 1).toString());
data.addValue(cost, "", name);
}
JFreeChart Chart = ChartFactory.createBarChart("Title, "Cost", "names", data, PlotOrientation.VERTICAL, false, false, false);
ChartFrame frame = new ChartFrame("Bars", Chart);
frame.setLocation(350, 100);
frame.pack();
frame.setVisible(true);