我创建了一个应用程序,将我在jtable中的数据显示到jfreechart中。我的jfreechart的版本是折线图。屏幕截图如下:
这是我的代码
public class LineChartDemo1 extends ApplicationFrame {
/**
* Creates a new demo.
*
* @param title the frame title.
*/
List<ReportChart> theDatas;
public LineChartDemo1(final String title, List<ReportChart> chartData) {
super(title);
this.theDatas = chartData;
final CategoryDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartPanel);
Main_Menu.presentase.removeAll(); // My form
Main_Menu.presentase.setLayout(new java.awt.BorderLayout()); // My form
Main_Menu.presentase.add(chartPanel); // My form
}
/**
* Creates a sample dataset.
*
* @return The dataset.
*/
private CategoryDataset createDataset() {
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
String algorithm1 = "Levensthein";
String algoritma2 = "SmithWaterman";
for (int i = 0; i < Main_Menu.jTable3.getRowCount(); i++) {
Object fileName = Main_Menu.jTable3.getValueAt(i, 1);
String fileNameToString = namaFile.toString();
Object nilaiLevensthein = Main_Menu.jTable3.getValueAt(i, 2);
double value1 = Double.parseDouble(nilaiLevensthein.toString());
Object nilaiSmithWaterman = Main_Menu.jTable3.getValueAt(i, 3);
double value2 = Double.parseDouble(nilaiSmithWaterman.toString());
dataset.addValue(value1, algoritma1, fileNameToString);
dataset.addValue(value2, algoritma2, fileNameToString);
}
return dataset;
}
private JFreeChart createChart(final CategoryDataset dataset) {
Object namaFile = Main_Menu.jTable3.getValueAt(0, 0);
String namaFileKeString = namaFile.toString();
// create the chart...
final JFreeChart chart = ChartFactory.createLineChart(
"Persentase Kemiripan", // chart title
"File-file Pembanding", // domain axis label
namaFileKeString, // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips
false // urls
);
chart.setBackgroundPaint(Color.white);
final CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setRangeGridlinePaint(Color.white);
// customise the range axis...
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
rangeAxis.setAutoRangeIncludesZero(true);
final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
//renderer.setDrawShapes(true);
renderer.setSeriesStroke(
0, new BasicStroke(
2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
1.0f, new float[]{10.0f, 6.0f}, 0.0f
)
);
renderer.setSeriesStroke(
1, new BasicStroke(
2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
1.0f, new float[]{6.0f, 6.0f}, 0.0f
)
);
renderer.setSeriesStroke(
2, new BasicStroke(
2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
1.0f, new float[]{2.0f, 6.0f}, 0.0f
)
);
return chart;
}
}
求助,非常感谢你。
edit
我成功地将x轴线上的标签设置为垂直 这是代码
private JFreeChart createChart(final CategoryDataset dataset) {
Object fileName = Main_Menu.jTable3.getValueAt(0, 0);
String fileNameToString = fileName.toString();
// create the chart...
final JFreeChart chart = ChartFactory.createLineChart(
"Persentation", // chart title
"comparingFile", // domain axis label
fileNameToString , // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips
false // urls
);
chart.setBackgroundPaint(Color.white);
ChartFactory.setChartTheme(StandardChartTheme.createDarknessTheme());
ChartUtilities.applyCurrentTheme(chart);
final CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setRangeGridlinePaint(Color.white);
final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
renderer.setShapesVisible(true);
renderer.setUseFillPaint(true);
renderer.setBaseItemLabelsVisible(true);
CategoryAxis catAxis = plot.getDomainAxis();
catAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
//catAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 16.0));
renderer.setSeriesStroke(
0, new BasicStroke(
2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
1.0f, new float[]{10.0f, 6.0f}, 0.0f
)
);
renderer.setSeriesStroke(
1, new BasicStroke(
2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
1.0f, new float[]{6.0f, 6.0f}, 0.0f
)
);
renderer.setSeriesStroke(
2, new BasicStroke(
2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
1.0f, new float[]{2.0f, 6.0f}, 0.0f
)
);
// OPTIONAL CUSTOMISATION COMPLETED.
return chart;
}
现在,第2点对我来说仍然是个谜 &#34;如何在会议轴值和轴类型中制作值标签?&#34;