JFreeChart散点图小例子

问题描述

请问哪个高手会JFreeChart插件制作散点图,请帮帮忙,现在急用,请给个小例子或者给解释一下都可以,请高手指点一下,谢谢……

解决方案

解决方案二:
引用楼主majingbo11011的回复:

请问哪个高手会JFreeChart插件制作散点图,请帮帮忙,现在急用,请给个小例子或者给解释一下都可以,请高手指点一下,谢谢……

我这有个可参考下。packagecom;importorg.jfree.ui.ApplicationFrame;importjava.awt.Color;importjava.awt.Dimension;importjava.text.NumberFormat;importjavax.swing.JPanel;importorg.jfree.chart.*;importorg.jfree.chart.axis.*;importorg.jfree.chart.plot.*;importorg.jfree.chart.renderer.category.LineAndShapeRenderer;importorg.jfree.chart.title.TextTitle;importorg.jfree.data.DataUtilities;importorg.jfree.data.DefaultKeyedValues;importorg.jfree.data.category.CategoryDataset;importorg.jfree.data.general.DatasetUtilities;importorg.jfree.ui.RefineryUtilities;importorg.jfree.util.SortOrder;publicclassParetoChartDemo1extendsApplicationFrame{publicParetoChartDemo1(Strings){super(s);JPaneljpanel=createDemoPanel();jpanel.setPreferredSize(newDimension(550,270));setContentPane(jpanel);}publicstaticJFreeChartcreateChart(CategoryDatasetacategorydataset[]){JFreeChartjfreechart=ChartFactory.createBarChart("FreshmeatSoftwareProjects","Language","Projects",acategorydataset[0],PlotOrientation.VERTICAL,true,true,false);jfreechart.addSubtitle(newTextTitle("ByProgrammingLanguage"));jfreechart.addSubtitle(newTextTitle("Asat5March2003"));jfreechart.setBackgroundPaint(Color.white);CategoryPlotcategoryplot=(CategoryPlot)jfreechart.getPlot();categoryplot.setBackgroundPaint(Color.lightGray);categoryplot.setRangeGridlinePaint(Color.white);CategoryAxiscategoryaxis=categoryplot.getDomainAxis();categoryaxis.setLowerMargin(0.02D);categoryaxis.setUpperMargin(0.02D);categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);NumberAxisnumberaxis=(NumberAxis)categoryplot.getRangeAxis();numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());LineAndShapeRendererlineandshaperenderer=newLineAndShapeRenderer();NumberAxisnumberaxis1=newNumberAxis("Percent");numberaxis1.setNumberFormatOverride(NumberFormat.getPercentInstance());categoryplot.setRangeAxis(1,numberaxis1);categoryplot.setDataset(1,acategorydataset[1]);categoryplot.setRenderer(1,lineandshaperenderer);categoryplot.mapDatasetToRangeAxis(1,1);categoryplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);returnjfreechart;}publicstaticCategoryDataset[]createDatasets(){DefaultKeyedValuesdefaultkeyedvalues=newDefaultKeyedValues();defaultkeyedvalues.addValue("C",newInteger(4843));defaultkeyedvalues.addValue("C++",newInteger(2098));defaultkeyedvalues.addValue("C#",newInteger(26));defaultkeyedvalues.addValue("Java",newInteger(1901));defaultkeyedvalues.addValue("Perl",newInteger(2507));defaultkeyedvalues.addValue("PHP",newInteger(1689));defaultkeyedvalues.addValue("Python",newInteger(948));defaultkeyedvalues.addValue("Ruby",newInteger(100));defaultkeyedvalues.addValue("SQL",newInteger(263));defaultkeyedvalues.addValue("UnixShell",newInteger(485));defaultkeyedvalues.sortByValues(SortOrder.DESCENDING);org.jfree.data.KeyedValueskeyedvalues=DataUtilities.getCumulativePercentages(defaultkeyedvalues);CategoryDatasetcategorydataset=DatasetUtilities.createCategoryDataset("Languages",defaultkeyedvalues);CategoryDatasetcategorydataset1=DatasetUtilities.createCategoryDataset("Cumulative",keyedvalues);return(newCategoryDataset[]{categorydataset,categorydataset1});}publicstaticJPanelcreateDemoPanel(){CategoryDatasetacategorydataset[]=createDatasets();JFreeChartjfreechart=createChart(acategorydataset);returnnewChartPanel(jfreechart);}publicstaticvoidmain(Stringargs[]){ParetoChartDemo1paretochartdemo1=newParetoChartDemo1("ParetoChartDemo1");paretochartdemo1.pack();RefineryUtilities.centerFrameOnScreen(paretochartdemo1);paretochartdemo1.setVisible(true);}}

解决方案三:
谢谢你啦,但是我现在想用一个散点图,你给的这个是柱形图和折线图……不过还是谢谢你啦……
解决方案四:

解决方案五:
等待……
解决方案六:
这是快速散点图,float的data存储数据。定义两个轴为XY。调用时传入标题,X轴上的数据,Y轴上的数据。packageanalysis;importorg.jfree.chart.ChartFrame;importorg.jfree.chart.JFreeChart;importorg.jfree.chart.axis.DateAxis;importorg.jfree.chart.axis.NumberAxis;importorg.jfree.chart.plot.FastScatterPlot;importorg.jfree.ui.RefineryUtilities;publicclassScatterPlot{publicstaticvoiddata(Stringtitle,String[]a,String[]b){float[][]data=newfloat[2][a.length];for(inti=0;i<a.length;i++){data[0][i]=Float.parseFloat(a[i]);data[1][i]=Float.parseFloat(b[i]);}finalDateAxisdomainAxis=newDateAxis("X");//domainAxis.setAutoRangeIncludesZero(false);finalNumberAxisrangeAxis=newNumberAxis("Y");rangeAxis.setAutoRangeIncludesZero(false);finalFastScatterPlotplot=newFastScatterPlot(data,domainAxis,rangeAxis);//FastScatterPlotplot1=ChartFactory.createScatterPlot(title,title,title,dataset,orientation,legend,tooltips,urls);finalJFreeChartchart=newJFreeChart(title,plot);ChartFrameframe=newChartFrame(title,chart);frame.pack();RefineryUtilities.centerFrameOnScreen(frame);frame.setVisible(true);}}

解决方案七:
java代码/****@paramxydatalist*@parambloods*@return*/publicstaticXYDatasetcreatexydataset(List<PressureBean>xydatalist,Stringbloods){DefaultXYDatasetxydataset=newDefaultXYDataset();intsize=xydatalist.size();double[][]datas=newdouble[2][size];for(inti=0;i<size;i++){PressureBeanpres=xydatalist.get(i);intsys=pres.getSyspress();//收缩压intdia=pres.getDiapress();//舒张压datas[0][i]=sys;datas[1][i]=dia;}xydataset.addSeries(bloods,datas);returnxydataset;}publicstaticJFreeChartcreateChart(XYDatasetxydataset,Stringbloodcattile,Stringshou,Stringshu,StringnobloodData,Stringbloods,Stringnomal,Stringfore,Stringone,Stringtwo,List<PressureBean>list,Loglog){//有可能用户在后面的版本中故意输入不正常数值,但是为了保证图片画图的完整,这里先计算//用户血压值的最大值。intmaxpress=160;intaddmax=20;if(list!=null&&list.size()>0){Iterator<PressureBean>it=list.iterator();while(it.hasNext()){PressureBeanpres=it.next();if(maxpress<pres.getDiapress()){maxpress=pres.getDiapress();}if(maxpress<pres.getSyspress()){maxpress=pres.getSyspress();}}maxpress+=addmax;log.info("highpressvalueis="+maxpress);}JFreeChartjfreechart=ChartFactory.createScatterPlot(bloodcattile,shou,shu,xydataset,PlotOrientation.VERTICAL,true,false,false);jfreechart.setBackgroundPaint(Color.white);jfreechart.setBorderPaint(Color.GREEN);jfreechart.setBorderStroke(newBasicStroke(1.5f));XYPlotxyplot=(XYPlot)jfreechart.getPlot();xyplot.setNoDataMessage(nobloodData);xyplot.setNoDataMessageFont(newFont("",Font.BOLD,14));xyplot.setNoDataMessagePaint(newColor(87,149,117));xyplot.setBackgroundPaint(newColor(255,253,246));ValueAxisvaaxis=xyplot.getDomainAxis();vaaxis.setAxisLineStroke(newBasicStroke(1.5f));ValueAxisva=xyplot.getDomainAxis(0);va.setAxisLineStroke(newBasicStroke(1.5f));va.setAxisLineStroke(newBasicStroke(1.5f));//坐标轴粗细va.setAxisLinePaint(newColor(215,215,215));//坐标轴颜色xyplot.setOutlineStroke(newBasicStroke(1.5f));//边框粗细va.setLabelPaint(newColor(10,10,10));//坐标轴标题颜色va.setTickLabelPaint(newColor(102,102,102));//坐标轴标尺值颜色ValueAxisaxis=xyplot.getRangeAxis();axis.setAxisLineStroke(newBasicStroke(1.5f));XYLineAndShapeRendererxylineandshaperenderer=(XYLineAndShapeRenderer)xyplot.getRenderer();xylineandshaperenderer.setSeriesOutlinePaint(0,Color.WHITE);xylineandshaperenderer.setUseOutlinePaint(true);NumberAxisnumberaxis=(NumberAxis)xyplot.getDomainAxis();numberaxis.setAutoRangeIncludesZero(false);numberaxis.setTickMarkInsideLength(2.0F);numberaxis.setTickMarkOutsideLength(0.0F);numberaxis.setAxisLineStroke(newBasicStroke(1.5f));numberaxis.setUpperBound(maxpress);numberaxis.setLowerBound(60);//最小值设置为60NumberAxisnumberaxis1=(NumberAxis)xyplot.getRangeAxis();numberaxis1.setTickMarkInsideLength(2.0F);numberaxis1.setTickMarkOutsideLength(0.0F);numberaxis1.setUpperBound(105d);numberaxis1.setLowerBound(35);numberaxis1.setAxisLineStroke(newBasicStroke(1.5f));//if(xydataset!=null){XYBoxAnnotationbox=newXYBoxAnnotation(0,0,89,59);//正常血压所在区域内边界XYBoxAnnotationbox1=newXYBoxAnnotation(0,0,119,79);//高血压前期所在区域内边界XYBoxAnnotationbox2=newXYBoxAnnotation(0,0,139,89);//高血压一期所在区域内边界XYBoxAnnotationbox3=newXYBoxAnnotation(0,0,159,99);//高血压二期所在区域内边界XYTextAnnotationtext1=newXYTextAnnotation(nomal,70,62.5);//标识“正常”XYTextAnnotationtext=newXYTextAnnotation(fore,70,82.5);//“高血压前期”XYTextAnnotationtext2=newXYTextAnnotation(one,70,91.5);//“高血压一期”XYTextAnnotationtext3=newXYTextAnnotation(two,70,101.5);//“高血压二期”//将上面的边界线条,说明文字加入到xyplot中。xyplot.addAnnotation(box);xyplot.addAnnotation(box1);xyplot.addAnnotation(box2);xyplot.addAnnotation(box3);xyplot.addAnnotation(text);xyplot.addAnnotation(text1);xyplot.addAnnotation(text2);xyplot.addAnnotation(text3);//}returnjfreechart;}publicstaticvoiddrawScatterChart(IrisIoInterfaceio,Loglog,XYDatasetxydataSet,Stringtitle,Stringshou,Stringshu,Stringnodata,Stringboolds,Stringnomal,Stringfore,Stringone,Stringtwo,List<PressureBean>list){JFreeChartchart=createChart(xydataSet,title,shou,shu,nodata,boolds,nomal,fore,one,two,list,log);HttpServletRequestrequest=io.getRequest();Stringfilename="";StringgraphURL="";try{filename=ServletUtilities.saveChartAsPNG(chart,400,300,null,io.getSession());graphURL=request.getContextPath()+"/displayChart?filename="+filename;}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();log.error(e);}io.setData("filename",filename,BeanShare.BEAN_SHARE_REQUEST);io.setData("scatterurl",graphURL,BeanShare.BEAN_SHARE_REQUEST);}

时间: 2024-12-02 22:45:05

JFreeChart散点图小例子的相关文章

jQuery点击弹出下拉菜单的小例子

这篇文章介绍了jQuery点击弹出下拉菜单的小例子,有需要的朋友可以参考一下   复制代码 代码如下: <title>导航--点击弹出内容</title>     <style type="text/css"> .navgation{margin:0;padding:0;list-style-type:none;position:relative;} .navgation li {float:left;} .navgation a{padding:3

JS实现QQ图片一闪一闪的效果小例子

这篇文章介绍了JS实现QQ图片一闪一闪的效果小例子,有需要的朋友可以参考一下   复制代码 代码如下: <HTML> <HEAD> <META http-equiv="Content-Type" content="text/html; charset=gb2312"> <TITLE>无标题文档</title> </HEAD> <BODY> <IMG id="imgId

子父窗口之间的操作之小例子

父窗口       用window.openr打开的子父窗口之间的操作跟框架的是不一样的,子窗口和父窗口之间有opener来联系.而源窗口要访问子窗口要通过其句柄来操作.以下小例子希望能帮助新手更了解他们的操作.test.htm <html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta name="GE

Java小例子

想当年学 BASIC 的时候,获取用户输入多简单,就一个 input:后来学 C, 也挺简单,一个 scanf():后来学 c++,同样简单,一个 cin <<:到了 Java 这里,麻烦来了. 1.简单的获取用户输入 下面是一个基本的例子,包含解释: 1.import java.io.BufferedReader; 2.import java.io.InputStreamReader; 3.import java.io.IOException; 4. 5.public class Basic

Lua时间转化的几个小例子

  这篇文章主要介绍了Lua时间转化的几个小例子,本文直接给出3段例子代码,需要的朋友可以参考下 1.把时间 秒,转化为xx天xx时xx分xx秒 的形式 代码如下: --把时间 秒,转化为xx天xx时xx分xx秒 的形式 function convertTimeForm(second) local timeDay = math.floor(second/86400) local timeHour = math.fmod(math.floor(second/3600), 24) local tim

ASP.Net获取客户端网卡MAC的小例子

这篇文章介绍了ASP.Net获取客户端网卡MAC的小例子,有需要的朋友可以参考一下   复制代码 代码如下: using System.Text.RegularExpressions; using System.Diagnostics; public class test {         public test         {}         public static string GetCustomerMac(string IP) //para IP is the clients

.net输出重写压缩页面文件的小例子

这篇文章介绍了.net输出重写压缩页面文件的小例子,有需要的朋友可以参考一下   不知你是否留意过,有一些网站的html代码都是混在一起,没有任何空格和换行等多余字符.它的好处不用多说--界面大小绝对优化.或许您在想,他 们这样做大大降低了可读性.的确,我们看是很乱,只能借用第三方软件重新布局代码.但是,我想他们开发时使用的源码不可能是混一团,前不久发现一个页面基 类,大概可以解释这个问题,不多说,看源码: 复制代码 代码如下: using System; using System.Data;

Android屏蔽后退键的小例子

这篇文章介绍了Android屏蔽后退键的小例子,有需要的朋友可以参考一下   复制代码 代码如下: public boolean onKeyDown(int keyCode, KeyEvent event) {          if (event.getAction() == KeyEvent.ACTION_DOWN                  && event.getKeyCode() == KeyEvent.KEYCODE_BACK) {              return

.net 读取非标准配置文件的小例子

这篇文章介绍了.net 读取非标准配置文件的小例子,有需要的朋友可以参考一下   代码如下: 复制代码 代码如下: public static string Config(string key)         {             ExeConfigurationFileMap file = new ExeConfigurationFileMap();             file.ExeConfigFilename = @"ProvidersProvider.config"