Boa noite pessoal. Tenho o seguinte source:
public class GerandoGrafico extends ApplicationFrame {
private Principal objeto = null;
private ExpressaoMatematica func = null;
public GerandoGrafico(Principal obj, String title) {
super(title);
objeto = obj;
//System.out.println(objeto.funcao.getText());
func = new ExpressaoMatematica(objeto.funcao.getText());
JPanel chartPanel = createPanel();
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(chartPanel);
//------------------------- TROCANDO O ÍCONE DA JANELA ----------------------//
/* BufferedImage image = null;
File file = new File("C:\\icone.png");
try {
image = ImageIO.read(file);
} catch (IOException e) {
e.printStackTrace();
}
this.setIconImage(image);*/
//----------------------------------------------------------------------------//
}
private XYDataset createDataset() {
double inicio = Double.valueOf(objeto.inicio_intervalo.getText());
double fim = Double.valueOf(objeto.fim_intervalo.getText());
//System.out.println(inicio);
//System.out.println(fim);
Function2D f1 = new Function2D() {
public double getValue(double x) {
//System.out.println(func.value(x));
return(func.value(x));
}
};
return(DatasetUtilities.sampleFunction2D(f1,inicio,fim, 100,"f(x)"));
}
private JFreeChart createChart(XYDataset dataset) {
// create the chart...
JFreeChart chart = ChartFactory.createXYLineChart(
"f(x) = " + objeto.funcao.getText(), // chart title
"Eixo X", // x axis label
"Eixo Y", // y axis label
dataset, // data
PlotOrientation.VERTICAL,
true, // include legend
true, // tooltips
false // urls
);
// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
chart.setBackgroundPaint(Color.white);
// get a reference to the plot for further customisation...
XYPlot plot = (XYPlot) chart.getPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
renderer.setShapesVisible(false);
XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false);
plot.setRenderer(1, renderer2);
// change the auto tick unit selection to integer units only...
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
// OPTIONAL CUSTOMISATION COMPLETED.
return(chart);
}
public JPanel createPanel() {
JFreeChart chart = createChart(createDataset());
return(new ChartPanel(chart));
}
public void iniciarGrafico() {
GerandoGrafico demo = new GerandoGrafico(objeto, "Gráfico da Função");
demo.pack();
//RefineryUtilities.centerFrameOnScreen(demo);
demo.setLocation(0, 0);
demo.setVisible(true);
}
}
Funciona perfeitamente para gerar o gráfico de uma determinada função. Eu gostaria agora de setar alguns pontos na curva da função representada, ou seja, dada a função: f(x) = x^2 + x + 1 eu gostaria de, por exemplo, nesta curva demarcar o ponto onde x=4. Alguém poderia me dar alguma dica de uma maneira simples de fazer esta implementação? Desde já agradeço!