如题,首先从一个文件里实时的读取数据,比如说 1秒钟读取一次,如果有更新,就再窗口中画出来,我想实时的画出一条曲线,横坐标就是1,2, 3, 4, 5 是一个number++,纵坐标是平均时间,average_delay,
文件格式就是:
1 16
2 18
3 19
4 21
::
::
其实可能不用先输入的文件里,然后再读出来,但是我想输出两条曲线,进行对比,比如
1 16 1 17
2 18 2 20
3 19 3 21
4 21 4 25
: : : :
: : : :
这种东西以前没接触过,各位有相关经验的朋友帮帮忙,应该怎么写。
文件格式就是:
1 16
2 18
3 19
4 21
::
::
其实可能不用先输入的文件里,然后再读出来,但是我想输出两条曲线,进行对比,比如
1 16 1 17
2 18 2 20
3 19 3 21
4 21 4 25
: : : :
: : : :
这种东西以前没接触过,各位有相关经验的朋友帮帮忙,应该怎么写。
而anychart和fuioncharts是通过js自动组装数据自动生成flash,它俩生成的是flash
加我QQ 聊: 445956202
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.title.LegendTitle;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.chart.plot.Plot;
import org.jfree.ui.RefineryUtilities;public class LineCharts extends ApplicationFrame { public LineCharts(String s) {
super(s);
setContentPane(createDemoLine());
} public static void main(String[] args) {
LineCharts fjc = new LineCharts("折线图");
fjc.pack();
RefineryUtilities.centerFrameOnScreen(fjc);
fjc.setBounds(10, 10, 800, 1600);
fjc.setVisible(true);
}
// 生成显示图表的面板 public static JPanel createDemoLine() {
JFreeChart jfreechart = createChart(createDataset());
jfreechart.setAntiAlias(true);
return new ChartPanel(jfreechart);
}
// 生成图表主对象JFreeChart public static JFreeChart createChart(DefaultCategoryDataset linedataset) {
// 定义图表对象
JFreeChart chart = ChartFactory.createLineChart("实验数据", // chart title
"时间", // domain axis label
" 率", // range axis label
linedataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips
false // urls
);
CategoryPlot plot = chart.getCategoryPlot();
// 设置图示字体
chart.getTitle().setFont(new Font("宋体", Font.BOLD, 22));
//设置横轴的字体
CategoryAxis categoryAxis = plot.getDomainAxis();
categoryAxis.setLabelFont(new Font("宋体", Font.BOLD, 14));//x轴标题字体
categoryAxis.setTickLabelFont(new Font("宋体", Font.BOLD, 12));//x轴刻度字体 //以下两行 设置图例的字体
LegendTitle legend = chart.getLegend(0);
legend.setItemFont(new Font("宋体", Font.BOLD, 14));
//设置竖轴的字体
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setLabelFont(new Font("宋体", Font.BOLD, 12)); //设置数轴的字体
rangeAxis.setTickLabelFont(new Font("宋体", Font.BOLD, 12)); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());//去掉竖轴字体显示不全
rangeAxis.setAutoRangeIncludesZero(true);
rangeAxis.setUpperMargin(0.20);
rangeAxis.setLabelAngle(Math.PI / 2.0); plot.getDomainAxis().setLowerMargin(-0.022d);
plot.getDomainAxis().setUpperMargin(0d);
return chart;
}// 生成数据
public static DefaultCategoryDataset createDataset() {
DefaultCategoryDataset linedataset = new DefaultCategoryDataset();
int i = 0;
int j = 0;
for (String ss : txt.txt("a.txt")) {
linedataset.addValue(Double.valueOf(ss), "一号试样", ("" + j + ":" + i));
i += 15;
if (60 == i) {
i = 0;
j++;
}
}
return linedataset;
}
}在同文件夹下建立a.txt 如下 是纵轴数据
15
13
30
32
23
23
23
23
1
2
5
4
44
7
4
2
74
for (String ss : txt.txt("a.txt")) {
linedataset.addValue(Double.valueOf(ss), "一号试样", ("" + j + ":" + i));
i += 15;
if (60 == i) {
i = 0;
j++;
}
}这段中的 txt.txt是什么意思,我这里报错了