Code
Code: Select all
import java.io.*;
import java.util.StringTokenizer;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.data.xy.*;
/**
* This class creates an XY chart using the data in gc.csv.
*
* @author R. Mark Volkmann, Object Computing, Inc.
*/
public class ChartCreator {
private static final boolean SHOW_LEGEND = false;
private static final boolean SHOW_TOOLTIPS = false;
private static final boolean GENERATE_URLS = false;
public static void main(String[] args) throws IOException {
FileReader fr;
fr = new FileReader("D:/gc.csv");
BufferedReader br = new BufferedReader(fr);
// Get the x-axis label from the first token in the first line
// and the y-axis label from the last token in the first line.
String line = br.readLine();
StringTokenizer st = new StringTokenizer(line, ",");
String xLabel = st.nextToken();
String yLabel = st.nextToken();
while (st.hasMoreTokens()) {
yLabel = st.nextToken();
}
String title = yLabel + " by " + xLabel;
// Get the data to plot from the remaining lines.
float minY = Float.MAX_VALUE;
float maxY = -Float.MAX_VALUE;
XYSeries series = new XYSeries("?");
while (true) {
line = br.readLine();
if (line == null) {
break;
}
st = new StringTokenizer(line, ",");
// The first token is the x value.
String xValue = st.nextToken();
// The last token is the y value.
String yValue = "";
while (st.hasMoreTokens()) {
yValue = st.nextToken();
}
float x = Float.parseFloat(xValue);
float y = Float.parseFloat(yValue);
series.add(x, y);
minY = Math.min(y, minY);
maxY = Math.max(y, maxY);
}
XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(series);
JFreeChart chart = ChartFactory.createXYLineChart(
title, xLabel, yLabel, dataset,
PlotOrientation.VERTICAL,
SHOW_LEGEND, SHOW_TOOLTIPS, GENERATE_URLS);
XYPlot plot = chart.getXYPlot();
plot.getRangeAxis().setRange(minY, maxY);
int width = 1000;
int height = 600;
ChartUtilities.saveChartAsPNG(
new File("D:/gc.png"), chart, width, height);
}
}
Code: Select all
Max Pause Goal,Minor Collections,Major Collections,Pause Count,Max Pause,GC Time,Total Time, Throughput
0,49,0,49,0.005,0.081,1.831,95.599
100,49,0,49,0.005,0.077,1.828,95.785
200,49,0,49,0.005,0.081,1.829,95.550
300,47,0,47,0.009,0.089,1.837,95.145
400,48,0,48,0.005,0.081,1.835,95.598
500,48,0,48,0.005,0.078,1.825,95.729
600,49,0,49,0.005,0.081,1.830,95.600
700,48,0,48,0.005,0.081,1.828,95.564
800,44,0,44,0.017,0.094,1.857,94.919
900,49,0,49,0.006,0.082,1.833,95.533
1000,49,0,49,0.005,0.088,1.840,95.224
my DataSet, I need "Time" is X. "Value 1", "Value 2", "Value 3" and "Value 4" is Y (multiple line).
Code: Select all
Time,Value 1,Value 2,Value 3,Value 4
1,0.357824926,0.356253751,0.356965197,0.351903118
2,0.35439012,0.347749191,0.357049848,0.356777756
3,0.355389286,0.353831366,0.354736911,0.350102632
4,0.356416076,0.356777756,0.356253751,0.353831366
Ray