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.