@@ -0,0 +1,1517 @@
+package org.mg.javalib.freechart;%0A%0Aimport java.awt.Color;%0Aimport java.awt.Dimension;%0A%0Aimport org.jfree.chart.ChartFactory;%0Aimport org.jfree.chart.ChartPanel;%0Aimport org.jfree.chart.JFreeChart;%0Aimport org.jfree.chart.plot.XYPlot;%0Aimport org.jfree.data.function.Function2D;%0Aimport org.jfree.data.general.DatasetUtilities;%0Aimport org.jfree.data.xy.XYDataset;%0Aimport org.mg.javalib.util.SwingUtil;%0A%0Apublic class FunctionPlot%0A%7B%0A%09private Function2D function2d;%0A%09private double lowerBound = 0;%0A%09private double upperBound = 1;%0A%09private int functionSamples = 1000;%0A%0A%09public FunctionPlot(Function2D function2d)%0A%09%7B%0A%09%09this.function2d = function2d;%0A%09%7D%0A%0A%09public ChartPanel getChartPanel()%0A%09%7B%0A%09%09XYDataset result = DatasetUtilities.sampleFunction2D(function2d, lowerBound, upperBound,%0A%09%09%09%09functionSamples, %22Function%22);%0A%09%09JFreeChart chart = ChartFactory.createXYLineChart(%22Title%22, %22X%22, %22Y%22, result);%0A%09%09XYPlot plot = chart.getXYPlot();%0A%0A%09%09plot.setBackgroundPaint(Color.WHITE);%0A%09%09plot.setDomainGridlinePaint(Color.GRAY);%0A%09%09plot.setRangeGridlinePaint(Color.GRAY);%0A%0A%09%09ChartPanel chartPanel = new ChartPanel(chart);%0A%09%09return chartPanel;%0A%09%7D%0A%0A%09public void setUpperBound(double upperBound)%0A%09%7B%0A%09%09this.upperBound = upperBound;%0A%09%7D%0A%0A%09public static void main(String%5B%5D args)%0A%09%7B%0A%09%09FunctionPlot fp = new FunctionPlot(new Function2D()%0A%09%09%7B%0A%09%09%09@Override%0A%09%09%09public double getValue(double x)%0A%09%09%09%7B%0A%09%09%09%09return Math.pow(x, 2);%0A%09%09%09%7D%0A%09%09%7D);%0A%09%09fp.setUpperBound(10.0);%0A%09%09SwingUtil.showInFrame(fp.getChartPanel(), new Dimension(600, 800));%0A%09%09System.exit(0);%0A%09%7D%0A%0A%7D%0A

add plot to draw a function