Опция 1
Очень полезная программа для генерации графиков на Unix: gnuplot .
Я также нашел скрипт csv2gnuplot , который вы могли быиспользовать в сценарии оболочки для пакетной обработки файлов.
Вариант 2
Если вы состоите в браке с решением ANT / Java (возможно, вы используете Windows), тогда я адаптировал следующий пример с использованием jfreechart
src / sample.csv
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
build.xml
<project name="demo" default="chart" xmlns:ivy="antlib:org.apache.ivy.ant">
<property name="build.dir" location="build"/>
<property name="input.file" location="src/sample.csv"/>
<property name="output.file" location="${build.dir}/sample.png"/>
<target name="init">
<ivy:resolve/>
<ivy:cachepath pathid="build.path" conf="build"/>
<mkdir dir="${build.dir}"/>
</target>
<target name="chart" depends="init">
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
<groovy>
import java.io.*;
import java.util.StringTokenizer;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.data.xy.*;
boolean SHOW_LEGEND = false;
boolean SHOW_TOOLTIPS = false;
boolean GENERATE_URLS = false;
FileReader fr = new FileReader(properties["input.file"]);
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 = 500;
int height = 300;
ChartUtilities.saveChartAsPNG(new File(properties["output.file"]), chart, width, height);
</groovy>
</target>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
</project>
ivy.xml
Плагин ivy позволяет ANT общаться с репозиториями Maven.
<ivy-module version="2.0">
<info organisation="org.myspotontheweb" module="demo"/>
<configurations defaultconfmapping="build->default">
<conf name="build" description="ANT tasks"/>
</configurations>
<dependencies>
<dependency org="org.codehaus.groovy" name="groovy-all" rev="1.8.2"/>
<dependency org="jfree" name="jfreechart" rev="1.0.13"/>
<dependency org="jfree" name="jcommon" rev="1.0.15" force="true"/>
</dependencies>
</ivy-module>
Примечание: В последней версии jfreechart нарушена зависимостьв версии 1.0.16 jcommon (отсутствует в Maven Central)