JFreechartは、Javaプラットフォームのオープンチャート描画クラスライブラリです。 Java言語で完全に書かれており、アプリケーション、アプレット、サーブレット、JSP向けに設計されています。 JFreechartは、パイチャート、バーチャート、散布プロット、時系列、ガントチャート、その他のチャートを生成でき、PNGおよびJPEG形式で出力を生成でき、PDFとExcelにも関連付けることができます。
ラインチャートの例
パッケージcom.sprite.test; java.io.fileをインポートします。 java.io.filenotfoundexceptionをインポートします。 java.io.fileoutputStreamをインポートします。 java.io.ioexceptionをインポートします。 Import org.jfree.chart.chartfactory; Import org.jfree.chart.chartutitivities; Import org.jfree.chart.jfreechart; Import org.jfree.chart.labels.StandardCategoryItemLabelGenerator; Import org.jfree.chart.plot.categoryplot; Import org.jfree.chart.plot.plotorientation; Import org.jfree.chart.renderer.category.lineandshaperender; Import org.jfree.data.category.categorydataset; Import org.jfree.data.general.datasetutitives; // jfreechart line chart(line chart)public class testjfreechart {/** * jfreechart lineチャート(ラインチャート) */public static void main(// string [] args){//ステップ1:カテゴリダタセットオブジェクト(データの準備)カテゴリダタセットデータセット= createdataset(); //ステップ2:データセットに従ってjfreechartオブジェクトを生成し、対応する設定を作成しますjfreechart freechart = createchart(dataset); //ステップ3:jfreechartオブジェクトをファイル、サーブレット出力ストリームなどに出力します。SaveeChart(freechart、 "e://line.jpg"、600、400); } //ファイルとして保存public static void saveasfile(jfreechartチャート、string outputpath、int weight、int height){fileoutputStream out = null; try {file outfile = new file(outputPath); if(!outfile.getParentFile()。exists()){outfile.getParentFile()。mkdirs(); } out = new fileoutputStream(outputPath); // pngとして保存// chartutilities.writechartaspng(out、chart、600、400); // jpeg chartutitivities.writechartasjpegとして保存(out、chart、600、400); out.flush(); } catch(filenotfoundexception e){e.printstacktrace(); } catch(ioexception e){e.printstacktrace(); }最後に{if(out!= null){try {out.close(); } catch(ioexception e){// do Nothing}}}}} // categorydatasetに基づいてjfreechartオブジェクトを作成しますpublic jfreechart createchart(categorydataset categorydataset){// jfreechartオブジェクトを作成:chartactory.createlinechart jfreechart jfreechart jfreechart jfreechart jfreechart jfreechart jfreechart jfreechart jffrechart jffrechart hour "、// title" year division "、// categoryaxislabel(カテゴリ軸、水平軸、x軸ラベル)「数量」、// valueaxislabel(value axis、垂直軸、y軸ラベル)categorydatasetなど// urls // categoryplotを使用して、さまざまなパラメーターを設定します。次の設定は省略できます。 categoryplot plot =(categoryplot)jfreechart.getplot(); //背景色の透明性plot.setbackgroundalpha(0.5f); //前景の色の透明性プロット。SetForeGroundalpha(0.5F); //その他の設定については、categoryplot class lineandshaperender renderer =(lineandshaperender)plot.getRenderer()を参照してください。 renderer.setBaseshapesVisible(true); //シリーズポイント(つまり、データポイント)は、renderer.setBaseLinesVisible(true)を表示することができます。 //シリーズポイント(つまり、データポイント)の間に接続があり、Renderer.SetUsEriesOffset(true)を見ることができます。 //オフセットrenderer.setBaseItemLabelgenerator(new StandardCategoryItemLabelGenerator())を設定します。 renderer.setBaseItemLabelsVisible(true); jfreechartを返します。 } / *** categorydataset object** / public static categorydataset createdataset(){string [] rowkeys = {"a platform"}; String [] colkeys = {"0:00"、 "1:00"、 "2:00"、 "7:00"、 "8:00"、 "9:00"、 "10:00"、 "11:00"、 "12:00"、 "13:00"、 "16:00"、 "20:00"、 "21:00"、 "23:00"; double [] [] data = {{4、3、1、1、1、1、2、2、2、1、8、2、1、1}、}; //または次のようなコードを使用します// categorydataset.addvalue(10、 "rowkey"、 "colkey"); DataSeTutitives.CreateCategoryDataset(RowKeys、Colkeys、Data)を返します。 }}レンダリングを生成します:
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。