好像可以实现的,我尝试了一下,自定义一个tickunit,然后在里边覆写valueToString方法控制输出,在需要显示值的地方返回值,不需要显示值的地方返回""就可以了.明天我把全部代码帖出来,你看看能不能解决你的问题.import java.text.NumberFormat;import org.jfree.chart.axis.NumberTickUnit;public class CustomTickUnit extends NumberTickUnit {
private boolean display = false; public CustomTickUnit(double size) {
super(size); } public CustomTickUnit(double size, boolean display, NumberFormat formatter) {
super(size, formatter);
this.display = display;
System.out.println("display value is " + display);
} /**
* Converts a value to a string.
*
* @param value
* the value.
*
* @return The formatted string.
*/
public String valueToString(double value) {
System.out.println ("get value is " + value + display);
if (((int) value) % 10 == 0) {
return super.valueToString(value);
} else {
return "";
}
} public void setDisplay(boolean display) {
this.display = display;
} public boolean isDisplay() {
return display;
}
}
private boolean display = false; public CustomTickUnit(double size) {
super(size); } public CustomTickUnit(double size, boolean display, NumberFormat formatter) {
super(size, formatter);
this.display = display;
System.out.println("display value is " + display);
} /**
* Converts a value to a string.
*
* @param value
* the value.
*
* @return The formatted string.
*/
public String valueToString(double value) {
System.out.println ("get value is " + value + display);
if (((int) value) % 10 == 0) {
return super.valueToString(value);
} else {
return "";
}
} public void setDisplay(boolean display) {
this.display = display;
} public boolean isDisplay() {
return display;
}
}
解决方案 »
- 谁能帮我(不是技术问题)
- java两个文件内容合并,排序输出
- ssh整合问题
- jfreechart折线图为横坐标换一种显示的问题
- spring+hibernate的问题...
- 关于cmp的问题-----------------基础.....求回答===========急
- 有没有学习EJB3的教程或资料?
- 600分 求J2EE开发经验,参与者有分
- [如果可以给800分]在Jbuilder和weblogic中如何实现下面的多对多的ejb(一个班级对多个教师,一个教师教多个班级,bjrkjsxx为bjxx和jsxx之
- 开发EJB2非要安装BAS5.0吗(我只有BAS4.5)?顺便问一下BAS5.0的下载地址和密码
- dom4j如何一次删除节点的所有属性?
- 有人用iBATIS吗?
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DecimalFormat;import javax.swing.JPanel;import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jfree.base.log.LogConfiguration;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.NumberTickUnit;
import org.jfree.chart.axis.TickUnitSource;
import org.jfree.chart.axis.TickUnits;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;public class AnnotationDemo1 extends ApplicationFrame {
private static Log log = LogFactory.getLog(AnnotationDemo1.class); /**
*
*/
private static final long serialVersionUID = 1L; public AnnotationDemo1(String s) {
super(s);
XYSeriesCollection xyseriescollection = createDataset();
JFreeChart jfreechart = createChart(xyseriescollection);
ChartPanel chartpanel = new ChartPanel(jfreechart);
chartpanel.setPreferredSize(new Dimension(360, 500));
setContentPane(chartpanel);
} private static XYSeriesCollection createDataset() {
XYSeriesCollection xyseriescollection = new XYSeriesCollection();
try {
BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(
new FileInputStream("D:/iems/framework-jfreechart/bin/wtageinf.txt")));
String s = bufferedreader.readLine();
s = bufferedreader.readLine();
s = bufferedreader.readLine();
s = bufferedreader.readLine();
XYSeries xyseries = new XYSeries("P3", true, true);
for (String s1 = bufferedreader.readLine(); s1 != null; s1 = bufferedreader
.readLine()) {
int i = Integer.parseInt(s1.substring(1, 8).trim());
float f = Float.parseFloat(s1.substring(9, 17).trim());
float f1 = Float.parseFloat(s1.substring(69, 86).trim());
if (i == 1) {
xyseries.add(f, f1);
}
s = bufferedreader.readLine();
s = bufferedreader.readLine();
s = bufferedreader.readLine();
s = bufferedreader.readLine();
s = bufferedreader.readLine();
} xyseriescollection.addSeries(xyseries);
} catch (FileNotFoundException filenotfoundexception) {
System.err.println(filenotfoundexception);
} catch (IOException ioexception) {
System.err.println(ioexception);
}
return xyseriescollection;
} private static JFreeChart createChart(XYDataset xydataset) {
JFreeChart jfreechart = ChartFactory.createXYLineChart(null,
"Age in Months", "kg", xydataset, PlotOrientation.VERTICAL, true, true,
false);
XYPlot xyplot = jfreechart.getXYPlot();
NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis();
numberaxis.setUpperMargin(0.12D);
numberaxis.setStandardTickUnits(createIntegerTickUnits());
log.debug(numberaxis.getStandardTickUnits());
//numberaxis.getStandardTickUnits().get
NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis();
numberaxis1.setAutoRangeIncludesZero(false); return jfreechart;
} public static JPanel createDemoPanel() {
JFreeChart jfreechart = createChart(createDataset());
return new ChartPanel(jfreechart);
}
public static TickUnitSource createIntegerTickUnits() { TickUnits units = new TickUnits();
DecimalFormat df0 = new DecimalFormat("0");
DecimalFormat df1 = new DecimalFormat("#,##0");
units.add(new CustomTickUnit(5,true, df0));
units.add(new CustomTickUnit(10,false, df0));
units.add(new CustomTickUnit(15,true, df0));
units.add(new CustomTickUnit(20, false,df0));
units.add(new CustomTickUnit(25, true,df0));
units.add(new CustomTickUnit(30, true,df0));
units.add(new CustomTickUnit(35, true,df0));
return units;}
public static void main(String args[]) {
// Log.getInstance().addTarget(new PrintStreamLogTarget(System.out));
LogConfiguration.setLogLevel("debug");
AnnotationDemo1 annotationdemo1 = new AnnotationDemo1("Annotation Demo 1");
annotationdemo1.pack();
RefineryUtilities.centerFrameOnScreen(annotationdemo1);
annotationdemo1.setVisible(true);
}
}
你取下来放到一个地方,然后修改一下程序中的文件路径
注意,要严格按照格式,从下一行开始全部拷贝到文件
Source: http://www.cdc.gov/nchs/about/major/nhanes/growthcharts/wtageinf.txt Age in
Sex Months L M S P3 P5 P10 P25 P50 P75 P90 P95 P97
1 0 1.815151075 3.530203168 0.152385273 2.355450986 2.52690402 2.773801848 3.150611082 3.530203168 3.879076559 4.17249339 4.34029274 4.446488308
1 0.5 1.547523128 4.003106424 0.146025021 2.799548641 2.964655655 3.209510017 3.597395573 4.003106424 4.387422565 4.718161283 4.910130108 5.032624982
1 1.5 1.068795548 4.879525083 0.136478767 3.614688072 3.774848862 4.020561446 4.428872952 4.879525083 5.327327567 5.728152752 5.967101615 6.121929103
1 2.5 0.695973505 5.672888765 0.129677511 4.34234145 4.503255345 4.754479354 5.183377547 5.672888765 6.175598158 6.638979132 6.921119162 7.106250132
1 3.5 0.41981509 6.391391982 0.124717085 4.992897896 5.157411653 5.416802856 5.866806254 6.391391982 6.942217106 7.460702368 7.781401145 7.993878049
1 4.5 0.219866801 7.041836432 0.121040119 5.575169066 5.744751566 6.01371624 6.484969167 7.041836432 7.635323002 8.202193202 8.556813353 8.793443663
1 5.5 0.077505598 7.630425182 0.1182712 6.096775274 6.272175299 6.551379244 7.043626918 7.630425182 8.262032991 8.871384112 9.255614546 9.51330656
1 6.5 -0.02190761 8.162951035 0.116153695 6.564430346 6.745992665 7.035656404 7.548345716 8.162951035 8.828786159 9.47546616 9.885435743 10.16135019
1 7.5 -0.0894409 8.644832479 0.114510349 6.984123338 7.171952393 7.472021438 8.004398775 8.644832479 9.34149038 10.02101374 10.45331433 10.74492376
1 8.5 -0.1334091 9.081119817 0.113217163 7.361236116 7.555286752 7.865532922 8.416718775 9.081119817 9.805593364 10.51406421 10.96573632 11.27083843
1 9.5 -0.1600954 9.476500305 0.11218624 7.700624405 7.90075516 8.220839211 8.789881892 9.476500305 10.22612395 10.96017225 11.42867623 11.74538465
1 10.5 -0.17429685 9.835307701 0.111354536 8.006677447 8.212683538 8.542195484 9.128109523 9.835307701 10.60772151 11.36445045 11.84763282 12.17435729
1 11.5 -0.1797189 10.16153567 0.110676413 8.283364855 8.494999555 8.833485623 9.43527941 10.16153567 10.9546603 11.73160184 12.2276612 12.56308347
1 12.5 -0.179254 10.45885399 0.110118635 8.534275028 8.751264252 9.098245709 9.714941801 10.45885399 11.27087147 12.06594792 12.57340193 12.91645043
1 13.5 -0.17518447 10.7306256 0.109656941 8.762648582 8.984701111 9.339687673 9.970337596 10.7306256 11.55996332 12.37145331 12.88910809 13.23893338
1 14.5 -0.16932268 10.97992482 0.109273653 8.971407287 9.198222429 9.560722369 10.20441778 10.97992482 11.82524099 12.65174864 13.17867019 13.53462171
1 15.5 -0.1631139 11.20955529 0.10895596 9.163180317 9.394453831 9.763981751 10.41986276 11.20955529 12.06972515 12.91015164 13.44563963 13.80724431
1 16.5 -0.15770999 11.4220677 0.108694678 9.340328068 9.575756968 9.951839998 10.61910138 11.4220677 12.29616991 13.14968707 13.6932508 14.0601935
1 17.5 -0.15402279 11.61977698 0.108483324 9.504964014 9.744250626 10.12643352 10.80432929 11.61977698 12.50708008 13.37310558 13.92444193 14.29654774
1 18.5 -0.15276214 11.80477902 0.108317416 9.658974787 9.901830339 10.28967982 10.97752662 11.80477902 12.70472779 13.58290165 14.14187481 14.51909298
1 19.5 -0.15446658 11.9789663 0.108193944 9.804039109 10.05018686 10.44329524 11.14047457 11.9789663 12.89116805 13.78133058 14.34795358 14.73034312
1 20.5 -0.15952202 12.14404334 0.108110954 9.941644878 10.19082308 10.58881155 11.2947714 12.14404334 13.06825426 13.9704249 14.54484233 14.93255878
1 21.5 -0.16817926 12.30154103 0.108067236 10.07310549 10.32507004 10.72759156 11.44184727 12.30154103 13.23765258 14.15200982 14.73448194 15.12776542
1 22.5 -0.1805668 12.45283028 0.108062078 10.19957488 10.45410181 10.86084353 11.58297823 12.45283028 13.40085582 14.3277181 14.91860604 15.31777023
1 23.5 -0.19670196 12.59913494 0.108095077 10.32206165 10.57894925 10.98963476 11.7192993 12.59913494 13.55919667 14.49900418 15.09875606 15.50417803
1 24.5 -0.21650121 12.74154396 0.108166005 10.4414422 10.70051298 11.11490406 11.85181666 12.74154396 13.71386029 14.6671577 15.27629562 15.68840631
1 25.5 -0.23979048 12.88102276 0.108274705 10.55847309 10.81957536 11.23747341 11.98141892 12.88102276 13.86589625 14.83331632 15.45242405 15.87169941
1 26.5 -0.26631585 13.01842382 0.108421024 10.67380261 10.93681171 11.35805876 12.10888759 13.01842382 14.0162298 14.99847794 15.62818936 16.05514188
1 27.5 -0.29575496 13.1544966 0.108604769 10.78798156 11.05280067 11.47727994 12.23490671 13.1544966 14.1656725 15.16351231 15.80450043 16.23967114
为曲线图设置数据集及各种设置:
public void makeChart(DayLoadApplet applet) {
applet.chart.getCategoryPlot().setDataset(this.getDataForFreeChart(applet));//此处的chart是用createLineChart方法生成的.
applet.chart.setBackgroundPaint(applet.getChartBGColor());
CategoryPlot categoryplot = (CategoryPlot) applet.chart.getPlot();
categoryplot.setBackgroundPaint(applet.getChartBGColor());//背景色
categoryplot.setRangeGridlinePaint(applet.getChartFGColor());//数据轴网格线条颜色
categoryplot.setDomainGridlinesVisible(true);//分类轴网格是否可见
categoryplot.setRangeGridlinesVisible(true);//数据轴网格是否可见 // 目录轴取得及设置
CategoryAxis categoryaxis = categoryplot.getDomainAxis();
categoryaxis.setTickLabelFont(new Font("Dilog", 0, 12));
categoryaxis.setTickLabelPaint(Color.WHITE);
// 设置标志显示角度
categoryaxis.setCategoryLabelPositions(CategoryLabelPositions
.createUpRotationLabelPositions(Math.PI / 2.0));
// 坐标文字从上自下排列,原来使用的是createUpRotationLabelRosition,文字是从下到上排列
categoryaxis.setCategoryLabelPositions(CategoryLabelPositions
.createDownRotationLabelPositions(Math.PI / 2.0));
// 设置坐标文字可用最大宽度与标准宽度的比率,这里使用3倍比率,应基本能保证10个汉字的正常显示.
categoryaxis.setMaximumCategoryLabelWidthRatio(3F);
NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
numberaxis.setAutoRangeIncludesZero(false);
numberaxis.setAutoRangeMinimumSize(30);
numberaxis.setTickLabelPaint(Color.WHITE);
numberaxis.setTickLabelFont(new Font("Dilog", 0, 12));
LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
lineandshaperenderer.setShape(new Rectangle(2,2));
lineandshaperenderer.setShapesFilled(true);
lineandshaperenderer.setShapesVisible(true);
lineandshaperenderer.setDrawOutlines(true);
lineandshaperenderer.setUseFillPaint(true); categoryplot.setForegroundAlpha(0.9F);
TextTitle textTitle = (TextTitle) applet.chart.getTitle();
textTitle.setFont(new Font("Dialog", 0, 16));
textTitle.setPaint(Color.WHITE);
// 图例显示位置
LegendTitle legendtitle = (LegendTitle) applet.chart.getSubtitle(0);
legendtitle.setItemFont(new Font("Dialog", 0, 12));
legendtitle.setItemPaint(Color.WHITE);
legendtitle.setBackgroundPaint(applet.getChartBGColor());
legendtitle.setPosition(RectangleEdge.BOTTOM);
}
得到数据集:
public CategoryDataset getDataForFreeChart(DayLoadApplet applet) {
DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int i = 1; i < applet.jtbGrid.getColumnCount(); i++) {
String serialName = getSelYMD(applet)
+ applet.jtbGrid.getColumnName(i).substring(0, 2) + "负荷曲线";
for (int j = 0; j < applet.jtbGrid.getRowCount(); j++) {
String xName= (applet.jtbGrid.getValueAt(j, 0)).toString();
Object value = applet.jtbGrid.getValueAt(j, i);
double dataValue = 0.0;
try {
dataValue = Double.parseDouble(value.toString());
} catch (Exception ex) {
dataValue = 0.0;
}
dataset.addValue(dataValue, serialName, xName);
}
} return dataset;
}
数据的基本格式:
时间 采集值 对照值 修正值
00:00 172.52 173.02 172.99
00:15 168.22 168.98 168.35
00:30 172.52 173.02 172.99
.....
.....
23:15 172.52 173.02 172.99
23:30 168.22 168.98 168.35
23:45 172.52 173.02 172.99
我最近也在研究jfreechart,在看源代码的时候想到了这个方法
项目中现在也准备使用
一起研究了,呵呵
不过我发现jfreechart设计的确实非常强大.
上班不开qq的
[email protected]
呵呵
只能用gmail了
好在gmail比较快.
最近比较忙
没大上csdn
有什么问题直接发邮件就是了.