drawing 2d graphics

Sorry, does anybody know the most convenient way to draw graphics? f.e to draw graphic just on two vectors of points X and Y. Rrd4J is not enough good because rrd works with time.
[186 byte] By [NikolayJavaa] at [2007-11-27 5:30:37]
# 1
the Graphics.drawLine(), .drawRect(), .fillRect(), etc. methods work pretty well.
bsampieria at 2007-7-12 14:55:03 > top of Java-index,Java Essentials,Java Programming...
# 2
Study this tutorial: http://java.sun.com/docs/books/tutorial/2d/index.htmlThen come back and ask the same question ;-)
Hippolytea at 2007-7-12 14:55:03 > top of Java-index,Java Essentials,Java Programming...
# 3

yes, sure Java 2D API is great, but the goal is not to develop that (drawing, scaling, etc...) from the beginning but to use something like rrd to create graphics.

Did you try http://www.epic.noaa.gov/java/sgt/? Or may be some other libraries that can do all that?

Thanks in advance.

NikolayJavaa at 2007-7-12 14:55:03 > top of Java-index,Java Essentials,Java Programming...
# 4
http://www.jfree.org/jfreechart/ ?
Hippolytea at 2007-7-12 14:55:03 > top of Java-index,Java Essentials,Java Programming...
# 5
> http://www.jfree.org/jfreechart/ ?Yes, great thanks! Will try that!
NikolayJavaa at 2007-7-12 14:55:03 > top of Java-index,Java Essentials,Java Programming...
# 6

To whom it may be interest.

This is a small example to draw a chart having "values on X" and "values on Y" :-) using JFreeChart

import java.awt.Font;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.IOException;

import javax.imageio.ImageIO;

import junit.framework.TestCase;

import org.jfree.chart.ChartFactory;

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.title.TextTitle;

import org.jfree.data.xy.XYDataset;

import org.jfree.data.xy.XYSeries;

import org.jfree.data.xy.XYSeriesCollection;

public class SimpleChartTest extends TestCase {

private XYSeriesCollection createDataset() {

XYSeriesCollection result = new XYSeriesCollection();

XYSeries s3 = new XYSeries("P", true, false);

s3.add(0, 2.355450986);

s3.add(0.5, 2.799548641);

s3.add(1.5, 3.614688072);

s3.add(11.5, 8.283364855);

s3.add(12.5, 8.534275028);

s3.add(13.5, 8.762648582);

s3.add(14.5, 8.971407287);

s3.add(15.5, 9.163180317);

s3.add(16.5, 9.340328068);

s3.add(17.5, 9.504964014);

s3.add(19.5, 9.804039109);

s3.add(20.5, 9.941644878);

result.addSeries(s3);

return result;

}

private JFreeChart createChart(XYDataset dataset) {

JFreeChart chart = ChartFactory.createXYLineChart(null,

"Value on X", "Value on Y", dataset, PlotOrientation.VERTICAL, true,

true, false);

TextTitle t1 = new TextTitle("Title1", new Font(

"SansSerif", Font.BOLD, 14));

TextTitle t2 = new TextTitle(

"Title2",

new Font("SansSerif", Font.PLAIN, 11));

chart.addSubtitle(t1);

chart.addSubtitle(t2);

XYPlot plot = chart.getXYPlot();

NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();

domainAxis.setUpperMargin(0.12);

domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

rangeAxis.setAutoRangeIncludesZero(false);

return chart;

}

public void test() throws IOException {

XYSeriesCollection dataset = createDataset();

JFreeChart chart = createChart(dataset);

BufferedImage image = chart.createBufferedImage(360, 500);

File file = new File("test-data/charts/newimage.png");

ImageIO.write(image, "png", file);

}

}

NikolayJavaa at 2007-7-12 14:55:03 > top of Java-index,Java Essentials,Java Programming...