日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

JFreeChart(五)之XY图

發(fā)布時間:2023/12/3 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JFreeChart(五)之XY图 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

轉(zhuǎn)載自??JFreeChart XY圖

在xy圖(散點(diǎn)圖)是根據(jù)一個數(shù)據(jù)系列組成的x和y值的列表。每個值對(x,y)是坐標(biāo)系中的一個點(diǎn)。這里1值確定水平(X)位置,而另一個確定垂直(Y)位置。本章演示了如何使用JFreeChart從一個給定的業(yè)務(wù)數(shù)據(jù)創(chuàng)建XY圖表。

業(yè)務(wù)數(shù)據(jù)

考慮這種情況,我們要創(chuàng)建一個XY圖表所有主要瀏覽器的一個例子。在這里,不同的性能分?jǐn)?shù)是從不同類型的人們聚集,如下所示:

FirefoxCategory(X)Score(Y)
1.01.0
2.04.0
3.03.0
ChromeCategory(X)Score(Y)
1.04.0
2.05.0
3.06.0
IECategory(X)Score(Y)
3.04.0
4.05.0
5.04.0

基于AWT的應(yīng)用

以下是對從上述給定的信息創(chuàng)建XY圖表的代碼。此代碼可以在AWT應(yīng)用程序嵌入一個XY圖表。

import java.awt.Color; import java.awt.BasicStroke; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RefineryUtilities; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.ChartFactory; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.xy.XYSeriesCollection; import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;public class XYLineChart_AWT extends ApplicationFrame {public XYLineChart_AWT( String applicationTitle, String chartTitle ){super(applicationTitle);JFreeChart xylineChart = ChartFactory.createXYLineChart(chartTitle ,"Category" ,"Score" ,createDataset() ,PlotOrientation.VERTICAL ,true , true , false);ChartPanel chartPanel = new ChartPanel( xylineChart );chartPanel.setPreferredSize( new java.awt.Dimension( 560 , 367 ) );final XYPlot plot = xylineChart.getXYPlot( );XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer( );renderer.setSeriesPaint( 0 , Color.RED );renderer.setSeriesPaint( 1 , Color.GREEN );renderer.setSeriesPaint( 2 , Color.YELLOW );renderer.setSeriesStroke( 0 , new BasicStroke( 4.0f ) );renderer.setSeriesStroke( 1 , new BasicStroke( 3.0f ) );renderer.setSeriesStroke( 2 , new BasicStroke( 2.0f ) );plot.setRenderer( renderer ); setContentPane( chartPanel ); }private XYDataset createDataset( ){final XYSeries firefox = new XYSeries( "Firefox" ); firefox.add( 1.0 , 1.0 ); firefox.add( 2.0 , 4.0 ); firefox.add( 3.0 , 3.0 ); final XYSeries chrome = new XYSeries( "Chrome" ); chrome.add( 1.0 , 4.0 ); chrome.add( 2.0 , 5.0 ); chrome.add( 3.0 , 6.0 ); final XYSeries iexplorer = new XYSeries( "InternetExplorer" ); iexplorer.add( 3.0 , 4.0 ); iexplorer.add( 4.0 , 5.0 ); iexplorer.add( 5.0 , 4.0 ); final XYSeriesCollection dataset = new XYSeriesCollection( ); dataset.addSeries( firefox ); dataset.addSeries( chrome ); dataset.addSeries( iexplorer );return dataset;}public static void main( String[ ] args ) {XYLineChart_AWT chart = new XYLineChart_AWT("Browser Usage Statistics", "Which Browser are you using?");chart.pack( ); RefineryUtilities.centerFrameOnScreen( chart ); chart.setVisible( true ); } }

讓我們保存XYLineChart_AWT.java文件如上面的Java代碼,然后從命令提示符下編譯并運(yùn)行它,如下所示:

$javac XYLineChart_AWT.java $java XYLineChart_AWT

如果一切順利,它會編譯并運(yùn)行生成以下XY圖:

?

創(chuàng)建JPEG圖像

讓我們重新編寫上面的例子,在命令行生成JPEG圖像。

import java.io.*; import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; import org.jfree.data.xy.XYSeries; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.xy.XYSeriesCollection; import org.jfree.chart.ChartUtilities; public class XYLineChart_image {public static void main( String[ ] args )throws Exception{final XYSeries firefox = new XYSeries( "Firefox" );firefox.add( 1.0 , 1.0 );firefox.add( 2.0 , 4.0 );firefox.add( 3.0 , 3.0 );final XYSeries chrome = new XYSeries( "Chrome" );chrome.add( 1.0 , 4.0 );chrome.add( 2.0 , 5.0 );chrome.add( 3.0 , 6.0 );final XYSeries iexplorer = new XYSeries( "InternetExplorer" );iexplorer.add( 3.0 , 4.0 );iexplorer.add( 4.0 , 5.0 );iexplorer.add( 5.0 , 4.0 );final XYSeriesCollection dataset = new XYSeriesCollection( );dataset.addSeries( firefox );dataset.addSeries( chrome );dataset.addSeries( iexplorer );JFreeChart xylineChart = ChartFactory.createXYLineChart("Browser usage statastics", "Category","Score", dataset,PlotOrientation.VERTICAL, true, true, false);int width = 640; /* Width of the image */int height = 480; /* Height of the image */ File XYChart = new File( "XYLineChart.jpeg" ); ChartUtilities.saveChartAsJPEG( XYChart, xylineChart, width, height);} }

讓我們保存在XYLineChart_image.java文件如上面的Java代碼,然后從命令提示符下編譯并運(yùn)行它,如下所示:

$javac XYLineChart_image.java $java XYLineChart_image

如果一切順利,它會編譯并運(yùn)行在當(dāng)前的目錄中創(chuàng)建JPEG圖像文件namedXYLineChart.jpeg。

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結(jié)

以上是生活随笔為你收集整理的JFreeChart(五)之XY图的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。