本文整理汇总了Java中org.jfree.chart.ChartUtilities类的典型用法代码示例。如果您正苦于以下问题:Java ChartUtilities类的具体用法?Java ChartUtilities怎么用?Java ChartUtilities使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ChartUtilities类属于org.jfree.chart包,在下文中一共展示了ChartUtilities类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeRankVSScore
import org.jfree.chart.ChartUtilities; //导入依赖的package包/类
public static void writeRankVSScore(File outputFile, List<SimilarityMatrix> matrices, int length, String add) throws Exception{
final DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
for(SimilarityMatrix m:matrices){
int[][] sortedIndizes=m.getIndizesOfSortedScores();
List<Double>[] scoreList=new List[Math.min(length,sortedIndizes[0].length)];
for(int i=0;i<scoreList.length;i++)scoreList[i]=new ArrayList<Double>();
for(int i=0;i<sortedIndizes.length;i++){
int l=0;
for(int j=0;j<sortedIndizes[i].length;j++){
double v=m.getSimilarityValue(i,sortedIndizes[i][j]);
if(!Double.isNaN(v)){
scoreList[l].add(v);
l++;
}
if(l>=scoreList.length)break;
}
}
for(int i=0;i<scoreList.length;i++)
dataset.add(scoreList[i], m.getMethodsQueryAndDBString(), i);
}
JFreeChart chart=ChartFactory.createBoxAndWhiskerChart("Whiskerplot", "Ranks", "Scores", dataset, true);
ChartUtilities.saveChartAsJPEG(new File(outputFile.getPath()+sep+add+"RankVSScore_"+getMethodsQueryStringFromList(matrices)+".jpg"), chart, Math.min(2000,length*100), 1000);
}
示例2: drawChart
import org.jfree.chart.ChartUtilities; //导入依赖的package包/类
public void drawChart(String filename, int width, int height) throws IOException {
// Create plot
NumberAxis xAxis = new NumberAxis(xAxisLabel);
NumberAxis yAxis = new NumberAxis(yAxisLabel);
XYSplineRenderer renderer = new XYSplineRenderer();
XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
plot.setAxisOffset(new RectangleInsets(4, 4, 4, 4));
// Create chart
JFreeChart chart = new JFreeChart(chartTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
ChartUtilities.applyCurrentTheme(chart);
ChartPanel chartPanel = new ChartPanel(chart, false);
// Draw png
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
Graphics graphics = bi.getGraphics();
chartPanel.setBounds(0, 0, width, height);
chartPanel.paint(graphics);
ImageIO.write(bi, "png", new File(filename));
}
示例3: writeRankVSPercentage
import org.jfree.chart.ChartUtilities; //导入依赖的package包/类
public static void writeRankVSPercentage(File outputFile, String add, List<ResultList>[] resultsOriginal, List<List<ResultList>>[] resultsDecoy, int length) throws Exception{
for(List<ResultList> o:resultsOriginal){
for(List<List<ResultList>> ds:resultsDecoy){
String name="RankVSpercentage";
if(ds.size()>1)name+="Mean";
Map<String,int[]> numbers=new TreeMap<String,int[]>();
for(List<ResultList> d:ds){
List<ResultList> merged=ResultList.mergeResults(new List[]{o,d});
for(int i=0;i<merged.size();i++){
ResultList rl=merged.get(i);
for(int j=0;j<Math.min(length,rl.results.size());j++){
String key=rl.query.getDB()+"-"+rl.results.get(j).getDB();
if(!numbers.containsKey(key))numbers.put(key, new int[length]);
numbers.get(key)[j]=numbers.get(key)[j]+1;
}
}
}
String fileName="";
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for(Entry<String, int[]> n:numbers.entrySet()){
double all=0;
for(int i=0;i<n.getValue().length;i++){
dataset.addValue(n.getValue()[i], n.getKey(), Integer.toString(i));
}
fileName+=n.getKey()+"---";
}
fileName=fileName.substring(0,fileName.length()-3);
final JFreeChart chart = ChartFactory.createBarChart("Boxplot","Ranks","Percentage",dataset);
ChartUtilities.saveChartAsJPEG(new File(outputFile.getPath()+"\\"+name+"_"+fileName+add+".jpg"), chart, Math.min(2000,length*100), 1000);
}
}
}
示例4: writeROCCurves
import org.jfree.chart.ChartUtilities; //导入依赖的package包/类
public static void writeROCCurves(File outputFile, TreeMap<String, HitStatistic> hits) throws Exception{
XYSeriesCollection dataset = new XYSeriesCollection();
for(Entry<String, HitStatistic> e:hits.entrySet()){
File txtFile=new File(outputFile.getAbsolutePath().replaceAll(".jpg","_"+e.getKey().split("-")[2]+".txt"));
BufferedWriter bw=new BufferedWriter(new FileWriter(txtFile));
XYSeries series= new XYSeries(e.getKey());
bw.write("false positive rate\tsensitivity");
bw.newLine();
List<double[]> roc=e.getValue().getROCAverage();
for(double[] r:roc){
bw.write(r[0]+"\t"+r[1]);
bw.newLine();
series.add(r[0],r[1]);
}
dataset.addSeries(series);
bw.close();
}
final JFreeChart chart =ChartFactory.createXYLineChart("ROCCurve", "false positive rate", "sensitivity", dataset);
ChartUtilities.saveChartAsJPEG(outputFile, chart, 1000, 400);
}
示例5: doSaveAs
import org.jfree.chart.ChartUtilities; //导入依赖的package包/类
/**
* Opens a file chooser and gives the user an opportunity to save the chart in PNG format.
*
* @throws IOException
* if there is an I/O error.
*/
@Override
public void doSaveAs() throws IOException {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(this.defaultDirectoryForSaveAs);
ExtensionFileFilter filter = new ExtensionFileFilter(localizationResources.getString("PNG_Image_Files"), ".png");
fileChooser.addChoosableFileFilter(filter);
int option = fileChooser.showSaveDialog(this);
if (option == JFileChooser.APPROVE_OPTION) {
String filename = fileChooser.getSelectedFile().getPath();
if (isEnforceFileExtensions()) {
if (!filename.endsWith(".png")) {
filename = filename + ".png";
}
}
ChartUtilities.saveChartAsPNG(new File(filename), this.chart, getWidth(), getHeight());
}
}
示例6: actionPerformed
import org.jfree.chart.ChartUtilities; //导入依赖的package包/类
public void actionPerformed(ActionEvent e) {
try{
if(fileChooser.showSaveDialog(null)==JFileChooser.APPROVE_OPTION){
String SelectedFileName = fileChooser.getSelectedFile().getAbsolutePath();
if(SelectedFileName.toUpperCase().endsWith(".JPG")||
SelectedFileName.toUpperCase().endsWith(".JPEG")){
ChartUtilities.saveChartAsJPEG(new File(SelectedFileName),TEdit,500,500);
return;
}
if(SelectedFileName.toUpperCase().endsWith(".PNG")){
ChartUtilities.saveChartAsPNG(new File(SelectedFileName),TEdit,500,500);
return;
}
ChartUtilities.saveChartAsPNG(new File(SelectedFileName+".png"),TEdit,500,500);
}
}
catch(Exception Ex){
System.out.println(Ex.toString());
}
}
示例7: doGet
import org.jfree.chart.ChartUtilities; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
List<PollOption> results = null;
try {
Long pollId = (Long) req.getSession().getAttribute("pollID");
results = DAOProvider.getDao().getPollOptions(pollId);
} catch (Exception ex) {
results = new ArrayList<>();
}
JFreeChart chart = DBUtility.getChart(results);
ChartUtilities.writeChartAsPNG(resp.getOutputStream(), chart, 700, 400);
}
示例8: doGet
import org.jfree.chart.ChartUtilities; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String resultFile = req.getServletContext().getRealPath(
"/WEB-INF/glasanje-rezultati.txt");
String definitionFile = req.getServletContext().getRealPath(
"/WEB-INF/glasanje-definicija.txt");
List<Band> results = ServerUtilty
.getResults(definitionFile, resultFile);
JFreeChart chart = ServerUtilty.getChart(results);
ChartUtilities.writeChartAsPNG(resp.getOutputStream(), chart, 700, 400);
resp.getOutputStream().flush();
}
示例9: saveChartAsPNG
import org.jfree.chart.ChartUtilities; //导入依赖的package包/类
/**
* Saves the chart as a PNG format file in the temporary directory and
* populates the ChartRenderingInfo object which can be used to generate
* an HTML image map.
*
* @param chart the chart to be saved (<code>null</code> not permitted).
* @param width the width of the chart.
* @param height the height of the chart.
* @param info the ChartRenderingInfo object to be populated (<code>null</code> permitted).
* @param session the HttpSession of the client.
*
* @return the filename of the chart saved in the temporary directory.
*
* @throws IOException if there is a problem saving the file.
*/
public static String saveChartAsPNG(JFreeChart chart, int width, int height,
ChartRenderingInfo info, HttpSession session)
throws IOException {
if (chart == null) {
throw new IllegalArgumentException("Null 'chart' argument.");
}
ServletUtilities.createTempDir();
File tempFile = File.createTempFile(
ServletUtilities.tempFilePrefix, ".png",
new File(System.getProperty("java.io.tmpdir"))
);
ChartUtilities.saveChartAsPNG(tempFile, chart, width, height, info);
ServletUtilities.registerChartForDeletion(tempFile, session);
return tempFile.getName();
}
示例10: saveChartAsJPEG
import org.jfree.chart.ChartUtilities; //导入依赖的package包/类
/**
* Saves the chart as a JPEG format file in the temporary directory and
* populates the ChartRenderingInfo object which can be used to generate
* an HTML image map.
*
* @param chart the chart to be saved (<code>null</code> not permitted).
* @param width the width of the chart
* @param height the height of the chart
* @param info the ChartRenderingInfo object to be populated
* @param session the HttpSession of the client
*
* @return the filename of the chart saved in the temporary directory
*
* @throws IOException if there is a problem saving the file.
*/
public static String saveChartAsJPEG(JFreeChart chart, int width, int height,
ChartRenderingInfo info, HttpSession session)
throws IOException {
if (chart == null) {
throw new IllegalArgumentException("Null 'chart' argument.");
}
ServletUtilities.createTempDir();
File tempFile = File.createTempFile(
ServletUtilities.tempFilePrefix,
".jpeg", new File(System.getProperty("java.io.tmpdir"))
);
ChartUtilities.saveChartAsJPEG(tempFile, chart, width, height, info);
ServletUtilities.registerChartForDeletion(tempFile, session);
return tempFile.getName();
}
示例11: doSaveAs
import org.jfree.chart.ChartUtilities; //导入依赖的package包/类
/**
* Opens a file chooser and gives the user an opportunity to save the chart
* in PNG format.
*
* @throws IOException if there is an I/O error.
*/
public void doSaveAs() throws IOException {
FileDialog fileDialog = new FileDialog(canvas.getShell(), SWT.SAVE);
String[] extensions = { "*.png" };
fileDialog.setFilterExtensions(extensions);
String filename = fileDialog.open();
if (filename != null) {
if (isEnforceFileExtensions()) {
if (!filename.endsWith(".png")) {
filename = filename + ".png";
}
}
//TODO replace getSize by getBounds ?
ChartUtilities.saveChartAsPNG(new File(filename), this.chart,
canvas.getSize().x, canvas.getSize().y);
}
}
示例12: saveChartAsPNG
import org.jfree.chart.ChartUtilities; //导入依赖的package包/类
/**
* Saves the chart as a PNG format file in the temporary directory and
* populates the {@link ChartRenderingInfo} object which can be used to
* generate an HTML image map.
*
* @param chart the chart to be saved (<code>null</code> not permitted).
* @param width the width of the chart.
* @param height the height of the chart.
* @param info the ChartRenderingInfo object to be populated
* (<code>null</code> permitted).
* @param session the HttpSession of the client (if <code>null</code>, the
* temporary file is marked as "one-time" and deleted by
* the {@link DisplayChart} servlet right after it is
* streamed to the client).
*
* @return The filename of the chart saved in the temporary directory.
*
* @throws IOException if there is a problem saving the file.
*/
public static String saveChartAsPNG(JFreeChart chart, int width, int height,
ChartRenderingInfo info, HttpSession session) throws IOException {
if (chart == null) {
throw new IllegalArgumentException("Null 'chart' argument.");
}
ServletUtilities.createTempDir();
String prefix = ServletUtilities.tempFilePrefix;
if (session == null) {
prefix = ServletUtilities.tempOneTimeFilePrefix;
}
File tempFile = File.createTempFile(prefix, ".png",
new File(System.getProperty("java.io.tmpdir")));
ChartUtilities.saveChartAsPNG(tempFile, chart, width, height, info);
if (session != null) {
ServletUtilities.registerChartForDeletion(tempFile, session);
}
return tempFile.getName();
}
示例13: GenerateRTMapPNG
import org.jfree.chart.ChartUtilities; //导入依赖的package包/类
private void GenerateRTMapPNG(XYSeriesCollection xySeriesCollection, XYSeries series, float R2) throws IOException {
new File(Workfolder + "/RT_Mapping/").mkdir();
String pngfile = Workfolder + "/RT_Mapping/" + FilenameUtils.getBaseName(LCMSA.mzXMLFileName).substring(0, Math.min(120, FilenameUtils.getBaseName(LCMSA.mzXMLFileName).length() - 1)) + "_" + FilenameUtils.getBaseName(LCMSB.mzXMLFileName).substring(0, Math.min(120, FilenameUtils.getBaseName(LCMSB.mzXMLFileName).length() - 1)) + "_RT.png";
XYSeries smoothline = new XYSeries("RT fitting curve");
for (XYZData data : regression.PredictYList) {
smoothline.add(data.getX(), data.getY());
}
xySeriesCollection.addSeries(smoothline);
xySeriesCollection.addSeries(series);
JFreeChart chart = ChartFactory.createScatterPlot("Retention time mapping: R2=" + R2, "RT:" + FilenameUtils.getBaseName(LCMSA.mzXMLFileName), "RT:" + FilenameUtils.getBaseName(LCMSB.mzXMLFileName), xySeriesCollection,
PlotOrientation.VERTICAL, true, true, false);
XYPlot xyPlot = (XYPlot) chart.getPlot();
xyPlot.setDomainCrosshairVisible(true);
xyPlot.setRangeCrosshairVisible(true);
XYItemRenderer renderer = xyPlot.getRenderer();
renderer.setSeriesPaint(1, Color.blue);
renderer.setSeriesPaint(0, Color.BLACK);
renderer.setSeriesShape(1, new Ellipse2D.Double(0, 0, 3, 3));
renderer.setSeriesStroke(1, new BasicStroke(3.0f));
renderer.setSeriesStroke(0, new BasicStroke(3.0f));
xyPlot.setBackgroundPaint(Color.white);
ChartUtilities.saveChartAsPNG(new File(pngfile), chart, 1000, 600);
}
示例14: doSaveAs
import org.jfree.chart.ChartUtilities; //导入依赖的package包/类
/**
* Opens a file chooser and gives the user an opportunity to save the chart
* in PNG format.
*
* @throws IOException if there is an I/O error.
*/
public void doSaveAs() throws IOException {
FileDialog fileDialog = new FileDialog(this.canvas.getShell(),
SWT.SAVE);
String[] extensions = {"*.png"};
fileDialog.setFilterExtensions(extensions);
String filename = fileDialog.open();
if (filename != null) {
if (isEnforceFileExtensions()) {
if (!filename.endsWith(".png")) {
filename = filename + ".png";
}
}
//TODO replace getSize by getBounds ?
ChartUtilities.saveChartAsPNG(new File(filename), this.chart,
this.canvas.getSize().x, this.canvas.getSize().y);
}
}
示例15: writeJChartToFile
import org.jfree.chart.ChartUtilities; //导入依赖的package包/类
static String writeJChartToFile(JFreeChart chart, File file, FileTypes fileType) throws IOException, DocumentException {
String fileName = file.getPath();
switch (fileType) {
case svg:
Tools.exportChartAsSVG(chart, new Rectangle(1000, 1000), file);
break;
case pdf:
Tools.exportChartAsPDF(chart, new Rectangle(500, 400), file);
break;
case jchart:
break;
case csv:
Tools.exportChartAsCSV(chart, file);
break;
default:
ChartUtilities.saveChartAsPNG(file, chart, 1000, 1000);
break;
}
return fileName;
}