- - PR -
JFreeChart複合グラフ2番目グラフを一番前に表示方法について
1
投稿者 | 投稿内容 |
---|---|
|
投稿日時: 2006-06-29 18:56
お世話になっています。
下記複合グラフを作りましたが、どうも2番目の折線グラフは 棒グラフの後に表示されています。(棒グラフに被されました。) 前面に表示する方法をご存知の方がいましたら、ご教授ください。 よろしくお願いいたします。 import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.Legend; import org.jfree.chart.StandardLegend; import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.CategoryLabelPositions; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.labels.CategoryLabelGenerator; import org.jfree.chart.labels.StandardCategoryLabelGenerator; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.DatasetRenderingOrder; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.renderer.category.BarRenderer; import org.jfree.chart.renderer.category.CategoryItemRenderer; import org.jfree.chart.renderer.category.LineAndShapeRenderer; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RefineryUtilities; public class OverlaidBarChartDemo extends ApplicationFrame { public OverlaidBarChartDemo(final String title) { super(title); // create the first dataset... DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); dataset1.addValue(1.0, "S1", "Category 1"); dataset1.addValue(4.0, "S1", "Category 2"); dataset1.addValue(3.0, "S1", "Category 3"); dataset1.addValue(5.0, "S1", "Category 4"); dataset1.addValue(0.0, "S1", "Category 5"); dataset1.addValue(0.0, "S1", "Category 6"); dataset1.addValue(0.0, "S1", "Category 7"); dataset1.addValue(0.0, "S1", "Category 8"); // create the first renderer... final CategoryLabelGenerator generator = new StandardCategoryLabelGenerator(); final CategoryItemRenderer renderer = new BarRenderer(); renderer.setLabelGenerator(generator); //renderer.setItemLabelsVisible(true); final CategoryPlot plot = new CategoryPlot(); plot.setDataset(dataset1); plot.setRenderer(renderer); plot.setDomainAxis(new CategoryAxis("Category")); plot.setRangeAxis(new NumberAxis("Value")); plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); // now create the second dataset and renderer... DefaultCategoryDataset dataset2 = new DefaultCategoryDataset(); dataset2.addValue(1.0, "T1", "Category 1"); dataset2.addValue(7.0, "T1", "Category 2"); dataset2.addValue(2.0, "T1", "Category 3"); dataset2.addValue(6.0, "T1", "Category 4"); dataset2.addValue(6.0, "T1", "Category 5"); dataset2.addValue(9.0, "T1", "Category 6"); dataset2.addValue(5.0, "T1", "Category 7"); dataset2.addValue(4.0, "T1", "Category 8"); final CategoryItemRenderer renderer2 = new LineAndShapeRenderer(); plot.setDataset(1, dataset2); plot.setRenderer(1, renderer2); // create the third dataset and renderer... final JFreeChart chart = new JFreeChart(plot); chart.setTitle("Overlaid Bar Chart"); chart.setLegend(new StandardLegend()); // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); } public static void main(final String[] args) { final OverlaidBarChartDemo demo = new OverlaidBarChartDemo("Overlaid Bar Chart Demo"); demo.pack(); RefineryUtilities.centerFrameOnScreen(demo); demo.setVisible(true); } } |
|
投稿日時: 2006-06-30 10:16
自力解決
以下のコードを追加 plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); |
1