1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| import java.awt.Color;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class Trwo extends ApplicationFrame {
public Trwo(final String title) {
super(title);
final XYDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(1200, 1100));
setContentPane(chartPanel);
}
private XYDataset createDataset() {
final XYSeries series1 = new XYSeries("SLMM");
final XYSeries series2 = new XYSeries("FSPM");
XYSeries series = new XYSeries("passage");
final XYSeriesCollection dataset = new XYSeriesCollection();
try {
FileInputStream fstream = new FileInputStream("/root/Bureau/data1");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
StringBuffer buffer = new StringBuffer();
while ((strLine = br.readLine()) != null) {
buffer.append(strLine);
}
String message = buffer.toString();
message = message.replaceAll(" ", ";");
message = message.replaceAll(" ", ";");
message = message.replaceAll(" ", ";");
message = message.replaceAll(";;", ";");
String[] splitMessage = message.split("\n");
for (int i = 14; i < splitMessage.length; i++) {
double x = 0.0, y = 0.0;
String algType = "direct";
String[] insideSplit = splitMessage[i].split(";");
if (insideSplit[0].equalsIgnoreCase("STEP:=")) {
algType = "indirect";
}
for (int j = 1; j < insideSplit.length; j++) {
String[] valueSplit = insideSplit[j].split(";");
if (valueSplit[0].equalsIgnoreCase("X")) {
x = Double.parseDouble(valueSplit[1]);
} else {
y = Double.parseDouble(valueSplit[1]);
}
//System.out.println(valueSplit[1]);
}
if (!algType.equalsIgnoreCase("direct")) {
System.out.println("X :" + x + " Y:" + y);
series1.add(x, y);
} else {
System.out.println("X :" + x + " Y:" + y);
series2.add(x, y);
}
}
dataset.addSeries(series1);
dataset.addSeries(series2);
} catch (Exception e) {
e.printStackTrace();
}
return dataset;
}
private JFreeChart createChart(final XYDataset dataset) {
final JFreeChart chart = ChartFactory.createXYLineChart(
"passage",
"X",
"Y",
dataset,
PlotOrientation.VERTICAL,
true,
true,
false);
chart.setBackgroundPaint(Color.white);
final XYPlot plot1 = chart.getXYPlot();
plot1.setBackgroundPaint(Color.lightGray);
plot1.setDomainGridlinePaint(Color.white);
plot1.setRangeGridlinePaint(Color.white);
final XYPlot plot2 = chart.getXYPlot();
plot2.setBackgroundPaint(Color.lightGray);
plot2.setDomainGridlinePaint(Color.white);
plot2.setRangeGridlinePaint(Color.white);
return chart;
}
public static void main(final String[] args) {
final Trwo demo = new Trwo("Multi Line Chart");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
} |
Partager