private static JFreeChart createChart ( String title , String xAxis , String yAxis1 , XYDataset dataset1 , String yAxis2 , XYDataset dataset2 ) { JFreeChart chart = ChartFactory . createXYLineChart ( title , xAxis , yAxis1 , dataset1 , PlotOrientation . VERTICAL , true , true , false ) ; final 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 ) ; final XYItemRenderer r = plot . getRenderer ( ) ; int count = Math . min ( dataset1 . getSeriesCount ( ) , dataset2 . getSeriesCount ( ) ) ; if ( r instanceof XYLineAndShapeRenderer ) { XYLineAndShapeRenderer renderer = ( XYLineAndShapeRenderer ) r ; renderer . setBaseStroke ( LINE ) ; renderer . setAutoPopulateSeriesPaint ( false ) ; renderer . setBaseShapesVisible ( false ) ; renderer . setBaseShapesFilled ( false ) ; renderer . setDrawSeriesLineAsPath ( true ) ; for ( int i = 0 ; i < count ; i ++ ) { renderer . setSeriesPaint ( i , COLORS . get ( i % COLORS . size ( ) ) ) ; } } chart . setBackgroundPaint ( Color . white ) ; // chart two { final NumberAxis axis2 = new NumberAxis ( yAxis2 ) ; axis2 . setAutoRangeIncludesZero ( false ) ; plot . setRangeAxis ( 1 , axis2 ) ; plot . setDataset ( 1 , dataset2 ) ; plot . mapDatasetToRangeAxis ( 1 , 1 ) ; final StandardXYItemRenderer renderer = new StandardXYItemRenderer ( ) ; renderer . setAutoPopulateSeriesPaint ( false ) ; renderer . setAutoPopulateSeriesStroke ( false ) ; renderer . setBaseShapesVisible ( false ) ; renderer . setBaseShapesFilled ( false ) ; renderer . setDrawSeriesLineAsPath ( true ) ; renderer . setBaseStroke ( DASHED ) ; for ( int i = 0 ; i < count ; i ++ ) { renderer . setSeriesPaint ( i , COLORS . get ( i % COLORS . size ( ) ) ) ; } plot . setRenderer ( 1 , renderer ) ; } return chart ; }
Creates a chart .