我需要在 JFreechart 中的 Timeseries 上获得钻石形状,但我无法做到。有人可以指导一下应该在下面的代码中添加什么代码来实现菱形点以及如何更改线条的颜色吗?
(该程序使用 rs 和 stmt 以及其他从 DB 派生并在其他地方定义的东西。该程序现在可以正常工作,唯一的问题是它看起来超级无聊。)
TimeSeries s1 = new TimeSeries("Technology", Day.class);
TimeSeries s2 = new TimeSeries("Entertainment", Day.class);
TimeSeries s3 = new TimeSeries("Soap", Day.class);
TimeSeries s4 = new TimeSeries("Music", Day.class);
TimeSeries s5 = new TimeSeries("Native", Day.class);
TimeSeries s6 = new TimeSeries("Speciality", Day.class);
TimeSeries s7 = new TimeSeries("Science", Day.class);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date plotdate;
if (!(combo_individualid.getModel().getSize() == 0)) {
String sql = ""
+ "SELECT * "
+ "FROM `customerbasetag` "
+ "WHERE `individual_idindividual` =? ";
try {
stmt = conn.prepareStatement(sql);
stmt.setString(1, combo_individualid.getSelectedItem().toString());
rs = stmt.executeQuery();
while (rs.next()) {
try {
plotdate = sdf.parse(rs.getString("session_date"));
s1.add(new Day(plotdate), new Integer(Integer.parseInt(rs.getString("technology"))));
s2.add(new Day(plotdate), new Integer(Integer.parseInt(rs.getString("entertainment"))));
s3.add(new Day(plotdate), new Integer(Integer.parseInt(rs.getString("soap"))));
s4.add(new Day(plotdate), new Integer(Integer.parseInt(rs.getString("music"))));
s5.add(new Day(plotdate), new Integer(Integer.parseInt(rs.getString("native"))));
s6.add(new Day(plotdate), new Integer(Integer.parseInt(rs.getString("speciality"))));
s7.add(new Day(plotdate), new Integer(Integer.parseInt(rs.getString("science"))));
} catch (ParseException ex) {
JOptionPane.showMessageDialog(null,
"Parse Exception" + ex.getMessage());
}
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null,
"Error During Session Select" + ex.getMessage());
}
/*NOTE: Chart plotting here*/
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(s1);
dataset.addSeries(s2);
dataset.addSeries(s3);
dataset.addSeries(s4);
dataset.addSeries(s5);
dataset.addSeries(s6);
dataset.addSeries(s7);
JFreeChart chart = ChartFactory.createTimeSeriesChart(
"TS Chart", "Date", "Value", dataset, true, true, false);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(true);
ChartFrame f = new ChartFrame("Individual Choice Evaluation", chart);
f.setVisible(true);
f.setSize(800, 600);
f.setLocationRelativeTo(null);
} else {
JOptionPane.showMessageDialog(null, "Please Select an Individual");
}
我已经更新了代码,但它仍然不能正常工作,我不断地拿回旧图表。继承人的代码。
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(s1);
dataset.addSeries(s2);
dataset.addSeries(s3);
dataset.addSeries(s4);
dataset.addSeries(s5);
dataset.addSeries(s6);
dataset.addSeries(s7);
JFreeChart chart = ChartFactory.createTimeSeriesChart("Time Series Chart for Individual id: "+combo_individualid.getSelectedItem().toString() , "Date", "Value", dataset, true, true, false);
Shape theShape = ShapeUtilities.createDiamond(1);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(true);
XYItemRenderer renderer = plot.getRenderer();
renderer.setSeriesShape(0, theShape);
renderer.setSeriesShape(1, theShape);
renderer.setSeriesShape(2, theShape);
renderer.setSeriesShape(3, theShape);
renderer.setSeriesShape(4, theShape);
renderer.setSeriesShape(5, theShape);
renderer.setSeriesShape(6, theShape);
ChartFrame f = new ChartFrame("Individual Choice Evaluation", chart);
f.setVisible(true);
f.setSize(800, 600);
f.setLocationRelativeTo(null);