我想在JFreeChart图表中组合一个折线图和一个条形图。目前我得到的是两条线。我必须以某种方式将其中一行的渲染器更改为BarRenderer
。这是我目前得到的:
barDataset = new TimeSeriesCollection();
lineDataset = new TimeSeriesCollection();
totalDistanceSeries = new TimeSeries("Total Distance");
movingAverageSeries = new TimeSeries("Moving Average");
while (rs.next()) {
myDate = rs.getDate("Date");
d = new Day(myDate);
totalDistance = rs.getDouble("TotaleAfstand");
movingAverage = rs.getDouble("MovingAverage");
totalDistanceSeries.add(d,totalDistance);
movingAverageSeries.add(d,movingAverage);
}
barDataset.addSeries(totalDistanceSeries);
lineDataset.addSeries(movingAverageSeries);
String chartTitle = "Monthly Chart with Moving Average";
String xAxisLabel = "Date";
String yAxisLabel = "TotalDistance";
JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle,
xAxisLabel, yAxisLabel, lineDataset);
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer();
renderer.setBaseShapesVisible(true);
XYPlot plot = (XYPlot) chart.getXYPlot();
plot.setDataset(1, barDataset);
chartPanel = new ChartPanel(chart);
chartPanel.setLocation(10,60);
chartPanel.setSize(1850, 900);
add(chartPanel);
有人知道怎么做吗?
我需要一个XYBarRenderer而不仅仅是BarRenderer。这是我在下面添加的代码情节。barDataset setDataset(1日);:
XYBarRenderer renderer2=new XYBarRenderer(0.20);
plot.setRenderer(1, renderer2);