Can anyone help me what would be the best way to transform a text file data into a trendchart... using a Jpanel!

The data file would have the type of errors and the quantity that each error has appeared...
Then in the Jpanel would get the trend chart composed by the type of errors and the bar with the qty..

Thank you in advance...

Recommended Answers

All 15 Replies

That is a fairly open-ended question. I think you first want to have a design for the chart. The design is going to be the hardest part of this problem, and I don't know how to advise you without some requirements...

Please what?

Show me what you are trying to achieve and maybe I can help.

As I said, design your chart to begin with (that is the hardest part). Once that is done, you will need to know some file I/O, maths functions, the swing package.

BUT, first you need to know what you are trying to do...

There's got to be some good libraries/tools out there that do the charting part of this. Then all you'd need to do is parse the text file and pull out the information you want to chart, and feed it to the APIs. I haven't worked with any myself, but I've seen them around from time to time...

JFreeChart has some charts such as that, but as already mentioned, you have to understand what you're charting to make much use of them.

Hi there.. you are right when you ask what i want!

the kind of result that i want is what i'm going to send you by e-mail... its a simple thing.... and the data is available in a text file... that i'm accessing and selecting the data that i want...

thanks in advance

regards,

commented: Read the Community Rules "Keep it on site" and stop the PMs. -3

Ok, so I got your sample input file, and a general overview of your graphs (bar & pie). The other guys have provided you with a api you could look at, which will make your life easier.

You are still seemingly providing us with the whole problem and not with specific areas you are struggling with, and I am sorry, but I'm not going to write your app for you.

Look at the api, see if you can get data from the file and present it in a way the api can use.

Thank you in advance...

what exactly are you thanking us for... because you got the option to quote someone?
well, you did that all on your own, I guess, well done.

if you want several people to be able to help you, mailing your stuff to one person won't really help, now will it?

post whatever you have on the forum here, make sure we can see where one class end, and where another begins (using Code tags would be a good start) and don't just provide us with a task.

unlike you, we won't get bad grades or in trouble at work if this project doesn't get up and running soon.

Well i'm sorry for being polite....

And i don't have a time schedule to follow... that is an idea that i want to implement...
The reality is that i have diferent equipments and every one of it provides an error log!
My application is collecting that error log and decript it
scanning it in order to calculate how many errors do we have regarding each single class of error!

creating a output file with the sum of each equipment

This way the file has the following layout

Errors qty
spcmsg 23
dbgfid 40
dbgini 10
Ekra1 73

Errors qty
spcmsg 60
dbgfid 70
dbgini 25
Ekra2 155

So my idea would be create Trend charts - Bar for every single equipment where i could have what were the top5 errors with the quantity...

and at the same time... another Chart - Pie with the Totals of each equipment

EKRA1 - 73
EKRA2 - 155

Yesterday i was almost sleeping i'm sorry about anything or if i ofend you! i'm just a newby..

Regards,

Once again: take a look at JFreeChart.

Thank you for the Tip... i'm reading the documentation related to Jfreechart...

Did you ever work with it? any advices?

Yes, we use it for some scatter plot and bar charts. There are many built-in graph types for various data series. Look through the demo jar that accompanies the download for a lot of examples of the various charts.

I think you are at a stage where you need to start producing some code to enable us to help you out more. Make sure next time you post, you have some code (use code tags too) you are struggling with (try make it relevant code, we don't need your whole program).

well after reading the manual and adapting some code of my own....

package Ekra;

import java.io.File;   
import java.io.FileInputStream;   
import java.io.InputStreamReader;   
import java.io.BufferedReader;   
import java.io.*;   
import java.util.*;   
import java.lang.NumberFormatException;   
import java.text.NumberFormat;   
import java.text.MessageFormat;   

import java.awt.Font;   
import javax.swing.JFrame;   
import javax.swing.JPanel;   
import org.jfree.chart.ChartFactory;   
import org.jfree.chart.ChartPanel;   
import org.jfree.chart.JFreeChart;   
import org.jfree.chart.plot.PiePlot;   
import org.jfree.data.general.DefaultPieDataset;   

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.plot.PlotOrientation;   
import org.jfree.chart.plot.XYPlot;   
import org.jfree.chart.renderer.xy.StandardXYItemRenderer;   
import org.jfree.data.*;   
import org.jfree.data.xy.XYDataset;   
import org.jfree.data.xy.XYSeries;   
import org.jfree.data.xy.XYSeriesCollection;   
import org.jfree.data.DomainOrder;   
import org.jfree.data.general.SeriesDataset;   
import org.jfree.data.category.DefaultCategoryDataset;   


public class graph extends JFrame{   

	/**
	 * 
	 */
	private static final long serialVersionUID = 0L;

	public graph(String title) throws Exception{   

		super(title);   

		XYDataset dataset = createDataset();   
		JFreeChart chart = createChart(dataset);   
		ChartPanel chartPanel = new ChartPanel(chart);   
		chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));   
		setContentPane(chartPanel);   
		chartPanel.setMouseZoomable(true, false);   
	}   


	// Well, here I read a file from a table in txt each line with 4 columns of numbers), save it in a string and then on a string 
	// Array of 4 elements. Then convert each element of the string to double (not know if I'm being very stupid, I am more beginner in java ...) 
	// What I'm trying to do is get two of those column (now in double) and put points on the method series.add below 
	// I think I have to do a loop of some way, then do what you suggested q ... But the loop that I did overwrite the variables 
	// My attempt was a normal access to the txt file

	/* public extrator extract(String) throws Exception {  
        File file = new File("F:\\Ekralog.txt");      
        FileInputStream in = new FileInputStream(file);  
        InputStreamReader convert = new InputStreamReader(in);  
        BufferedReader bf = new BufferedReader(convert);  
        String line;  
        String[] element;  
        line = bf.readLine();  
        element = line.split("[\\s]+");  
        bf.close();  
        in.close();return  

	 */   


	private XYDataset createDataset() throws Exception {   
		//CONVERT STRING TO DOUBLE   
		//double element0;     
		//element0 = Double.parseDouble(element[0]); /* element[0] its one string*/   

		XYSeries series1 = new XYSeries("TRZ");   
		series1.add(1.0, 1.0); // some point that i've inserted to test and it is
		series1.add(2.0, 4.0);// should i do a loop to test it.. there are more than 100 points
		series1.add(3.0, 3.0);   
		series1.add(4.0, 5.0);   
		series1.add(5.0, 5.0);   
		series1.add(6.0, 7.0);   
		series1.add(7.0, 7.0);   
		series1.add(8.0, 8.0);   



		XYSeriesCollection dataset = new XYSeriesCollection();   
		dataset.addSeries(series1);   

		return dataset;   


	}   
	// ListDouble colunas = new ArrayListDouble();   

	//public ListDouble getColunas(){   

	//    return colunas;   

	// }   


	private JFreeChart createChart(XYDataset dataset) {   
		// create the chart...   
		JFreeChart chart = ChartFactory.createXYLineChart(   
				"Medida", // chart title   
				"X", // x axis label   
				"Y", // y axis label   
				dataset, // data   
				PlotOrientation.VERTICAL,   
				true, // include legend   
				true, // tooltips   
				false // urls   

		);   

		return chart;   
	}   

	public static void main(String[] args) throws Exception {   
		graph teste = new graph("test");   
		teste.pack();   
		teste.setVisible(true);   
	}   

}

i have some dificulties regarding the translation of the data of the txt file... is not plotting...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.