资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

使用JFreeChart怎么动态画折线图

今天就跟大家聊聊有关使用JFreeChart怎么动态画折线图,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

创新互联公司"三网合一"的企业建站思路。企业可建设拥有电脑版、微信版、手机版的企业网站。实现跨屏营销,产品发布一步更新,电脑网络+移动网络一网打尽,满足企业的营销需求!创新互联公司具备承接各种类型的成都网站建设、做网站项目的能力。经过10多年的努力的开拓,为不同行业的企事业单位提供了优质的服务,并获得了客户的一致好评。

需要的jar包是:gnujaxp.jar,jcommon-1.0.16.jar,jfreechart-1.0.13.jar

public class JFreeZheXianTest{

 public static XYSeries xyCPUseries = new XYSeries("CPU");

 public static int hundroud = 0;
 public static JFreeChart jfreechart = null;

 public JPanel getCPUJFreeChart(){

 jfreechart = ChartFactory.createXYLineChart(
  null, null, null, createDataset1(),
  PlotOrientation.VERTICAL, false, true, false);

 StandardChartTheme mChartTheme = new StandardChartTheme("CN");
 mChartTheme.setLargeFont(new Font("黑体", Font.BOLD, 20));
 mChartTheme.setExtraLargeFont(new Font("宋体", Font.PLAIN, 15));
 mChartTheme.setRegularFont(new Font("宋体", Font.PLAIN, 15));
 ChartFactory.setChartTheme(mChartTheme);

 jfreechart.setBorderPaint(new Color(0,204,205));
 jfreechart.setBorderVisible(true);

 XYPlot xyplot = (XYPlot) jfreechart.getPlot();

 // Y轴
 NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
 numberaxis.setLowerBound(0);
 numberaxis.setUpperBound(100);
 numberaxis.setTickUnit(new NumberTickUnit(100d));
 // 只显示整数值
 numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
 // numberaxis.setAutoRangeIncludesZero(true);
 numberaxis.setLowerMargin(0); // 数据轴下(左)边距 ­
 numberaxis.setMinorTickMarksVisible(false);// 标记线是否显示
 numberaxis.setTickMarkInsideLength(0);// 外刻度线向内长度
 numberaxis.setTickMarkOutsideLength(0);

 // X轴的设计
 NumberAxis x = (NumberAxis) xyplot.getDomainAxis();
 x.setAutoRange(true);// 自动设置数据轴数据范围
 // 自己设置横坐标的值
 x.setAutoTickUnitSelection(false);
 x.setTickUnit(new NumberTickUnit(60d));
 // 设置最大的显示值和最小的显示值
 x.setLowerBound(0);
 x.setUpperBound(60);
 // 数据轴的数据标签:只显示整数标签
 x.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
 x.setAxisLineVisible(true);// X轴竖线是否显示
 x.setTickMarksVisible(false);// 标记线是否显示

 RectangleInsets offset = new RectangleInsets(0, 0, 0, 0);
 xyplot.setAxisOffset(offset);// 坐标轴到数据区的间距
 xyplot.setBackgroundAlpha(0.0f);// 去掉柱状图的背景色
 xyplot.setOutlinePaint(null);// 去掉边框

 // ChartPanel chartPanel = new ChartPanel(jfreechart);
 // chartPanel.restoreAutoDomainBounds();//重置X轴

 ChartPanel chartPanel = new ChartPanel(jfreechart, true);

 return chartPanel;
 }

 /**
 * 该方法是数据的设计
 * 
 * @return
 */
 public static XYDataset createDataset1() {
 XYSeriesCollection xyseriescollection = new XYSeriesCollection();
 xyseriescollection.addSeries(xyCPUseries);
 return xyseriescollection;
 }

 /**
 * 随机生成的数据
 */
 public static void dynamicRun() {
 int i = 0;
 while (true) {

  double factor = Math.random()*100;

  hundroud = (int)factor;
  jfreechart.setTitle("CPU的大小是:  "+hundroud+"%");
  jfreechart.getTitle().setFont(new Font("微软雅黑", 0, 16));//设置标题字体

  xyCPUseries.add(i, factor);

  try {
  Thread.currentThread();
  Thread.sleep(1000);
  } catch (InterruptedException e) {
  e.printStackTrace();
  }
  i++;
  if (i == 60){
  i=0;
  xyCPUseries.delete(0, 59);
  continue;
  }
 }
 }

 public static void main(String[] args) {
 JFreeZheXianTest jz = new JFreeZheXianTest();
 JFrame frame = new JFrame();
 frame.setSize(700, 500);
 frame.getContentPane().add(jz.getCPUJFreeChart(), BorderLayout.CENTER);

 frame.setVisible(true);
 frame.setLocationRelativeTo(null); // 窗口居于屏幕正中央
 frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
 dynamicRun();
 }
}

看完上述内容,你们对使用JFreeChart怎么动态画折线图有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。


文章题目:使用JFreeChart怎么动态画折线图
新闻来源:http://cdkjz.cn/article/ghgpdh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220