JFreeChart不会在线程的每次迭代中显示图形? [英] JFreeChart does not show the graph at every iteration on thread?

查看:131
本文介绍了JFreeChart不会在线程的每次迭代中显示图形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个类中使用线程获取计数器值,并在另一个线程中写入 JFreeChart 。在执行时,它可以交替工作,但只在最后显示图形。它还将y轴标签值显示为Float,但实际检索值为int。如何解决这些问题?

  XYDataset Dataset; 
TimeSeries Series =新的TimeSeries(随机数据);
秒秒=新秒();
ChartPanel CPanel;
Value = Integer.parseInt(MySQLClass.Map_MySql.get(+ MainWindow.SelectedNode +));

String CounterName = MainWindow.SelectedNode.toString();
Series.add(sec,Value);
Dataset = new TimeSeriesCollection(Series);
System.out.println(Ds =+ Dataset);
Chart = ChartFactory.createTimeSeriesChart(CounterName,Time,Range,Dataset,true,false,false);
System.out.println(Chart Created);
XYPlot Plot =(XYPlot)Chart.getPlot();
Plot.setBackgroundPaint(Color.LIGHT_GRAY);
Plot.setDomainGridlinePaint(Color.WHITE);
Plot.setRangeGridlinePaint(Color.RED);
Panel1.revalidate();
CPanel =新ChartPanel(图表);
CPanel.setVisible(true);
Panel1.add(CPanel);
System.out.println(Chart Added);
Panel1.validate();

Thread.sleep((int)MainWindow.Interval_Combo.getSelectedItem()* 1000);
System.gc();

访问这两个类的线程



<$ (true)
{
MySQLClass m = new MySQLClass(); p $ p>
线程t1 =新线程(m);
t1.start();
t1.join();
Graph g = new Graph();
线程t2 =新线程(g);
t2.start();
t2.join();

在MySql类中,我必须获取计数器名称和值并将其存储

  while(rs.next())
{
Map_MySql。HashMap以下列方式调用Map_Mysql。 put(rs.getString(1),rs.getString(2));
}

我不知道实际的问题,请解决这个问题。输出看起来像,

MySql Occur

com.mysql.jdbc.JDBC4Connection@2c8ab0

图形发生

42913

Ds=org.jfree.data.time.TimeSeriesCollection@c204e809

MySql发生 -
com.mysql.jdbc。 JDBC4Connection @ 1930b4b

图形发生

44217



最后显示浮点值Y轴为最后一个值,没有图形表示。

解决方案

对于第二个问题(整数轴标签而不是float),可以通过调用 setStandardTickUnits( )方法。您可以传递任何 TickUnitSource ,但最简单的你可能是 NumberAxis.createIntegerTickUnits()


I am getting counter values in one class using a thread and writing JFreeChart in another thread. While executing, it works alternatively, but only shows the graph at the end. It also displays the y axis label value as a Float but the actual retrieval value is int. How can I solve these issues?

        XYDataset Dataset;
        TimeSeries Series = new TimeSeries("Random Data");
        Second sec = new Second();
        ChartPanel CPanel;
        Value = Integer.parseInt(MySQLClass.Map_MySql.get(""+MainWindow.SelectedNode+""));

        String CounterName = MainWindow.SelectedNode.toString();
        Series.add(sec, Value);
        Dataset = new TimeSeriesCollection(Series);
        System.out.println("Ds="+Dataset);
        Chart = ChartFactory.createTimeSeriesChart(CounterName, "Time", "Range", Dataset, true, false, false);
        System.out.println("Chart Created");
        XYPlot Plot = (XYPlot)Chart.getPlot();
        Plot.setBackgroundPaint(Color.LIGHT_GRAY);
        Plot.setDomainGridlinePaint(Color.WHITE);
        Plot.setRangeGridlinePaint(Color.RED);
        Panel1.revalidate();
        CPanel = new ChartPanel(Chart);
        CPanel.setVisible(true);
        Panel1.add(CPanel);
        System.out.println("Chart Added");
        Panel1.validate();

        Thread.sleep((int)MainWindow.Interval_Combo.getSelectedItem() * 1000);
        System.gc();

This thread for accessing those two class

        while(true)
        {
            MySQLClass m = new MySQLClass();
            Thread t1 = new Thread(m);
            t1.start();
            t1.join();
            Graph g = new Graph();
            Thread t2 = new Thread(g);
            t2.start();
            t2.join();
        }

In MySql class, i hust get the counter name and value and store it in Hashmap called Map_Mysql in followiung manner.

   while(rs.next())
   {
     Map_MySql.put(rs.getString(1), rs.getString(2));
   }

I dont know what the actual problem, please solve this. Output look like,

MySql Occur
com.mysql.jdbc.JDBC4Connection@2c8ab0
Graph Occur
42913
Ds=org.jfree.data.time.TimeSeriesCollection@c204e809
MySql Occur
com.mysql.jdbc.JDBC4Connection@1930b4b
Graph Occur
44217

At the end show the graph with float value in Y axis for last value with no graphical representation.

解决方案

For your second question (integer axis labels instead of float), this can be handled by calling the setStandardTickUnits() method on the axis. You can pass any TickUnitSource, but easiest for you is probably NumberAxis.createIntegerTickUnits().

这篇关于JFreeChart不会在线程的每次迭代中显示图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆