Thursday 15 May 2014

java - Creating a normal distribution graph with JFreeChart -


I am trying to create a normal distribution graph using the JFreeChart library. If I try to get an area below the graph, then I am successful. Although I could not find any way about how to get 2 areas under the graph.

Here is the code for one side:

  public GraphHujungKanan () {Function2D normal = new normal distribution function 2D (0.0, 1.0); Dataset = dataset topilization. Sample Function 2D (normal, -4, 4, 100, "normal"); XYSeries fLine = new XYSeries ("fill"); FLine.add (Cinematic, 0); FLine.add (4, 0); (XYSeriesCollection) dataset) .addSeries (fLine); Number xxx = new number axis (empty); Numberxaxxx = new number axis (empty); XYDifferenceRenderer Renderer = New XYDifferenceRenderer (); XAxis.setRange (0, 5); Plot = new XYPlot (dataset, xaxis, yAxis, renderer); Chart = new GeFree chart (plot); Chart.removeLegend (); ChartPanel CP = New ChartPanel (Chart); This.add (cp); }   

How does this look with the above code

Here it looks like with the code above

And here's where I need to see it:

 Enter the image details here

I have already tried to flip the positive and negative values ​​but instead the graph line changes to green is.

This is what I tried

  public GrafDuaHujung () {Function2D normal = new NormalDistributionFunction2D (0.0, 1.0); Dataset = dataset topilization. Sample Function 2D (normal, -4, 4, 100, "normal"); // XYSeries fLine = New XYSeries ("fine") on the right side of the line; FLine.add (2, 0); FLine.add (4, 0); (XYSeriesCollection) dataset) .addSeries (fLine); // XYSeries DLin on the left side of the line = New XYSeries ("dLine"); DLine.add (-2, 0); DLine.add (-4, 0); (XYSeriesCollection) dataset) .addSeries (dLine); Number xxx = new number axis (empty); Numberxaxxx = new number axis (empty); XYDifferenceRenderer Renderer = New XYDifferenceRenderer (); XAxis.setRange (0, 5); Plot = new XYPlot (dataset, xaxis, yAxis, renderer); Chart = new GeFree chart (plot); Chart.removeLegend (); ChartPanel CP = New ChartPanel (Chart); This.add (cp); }   

Thank you for your reply.

You can use multiple datasets.

  public GrafDuaHujung () {Function2D generic = new NormalDistributionFunction2D (0.0, 1.0); Dataset = dataset topilization. Sample Function 2D (normal, -4, 4, 100, "normal"); Dataset 2 = Dataset Optimization Sample Function 2D (normal, -4, 4, 100, "normal"); // New // line on the right XYSeries fLine = New XYSeries ("fine"); FLine.add (2, 0); FLine.add (4, 0); (XYSeriesCollection) dataset) .addSeries (fLine); // XYSeries DLin on the left side of the line = New XYSeries ("dLine"); DLine.add (-2, 0); DLine.add (-4, 0); (XYSeriesCollection) Dataset 2) .addSeries (dLine); // Changed XYDifferenceRenderer Renderer = New XYDifferenceRenderer (); Plot = new XYPlot (); // New conspiracy .setsetset (0, dataset); // new conspiracy .cdetsetset (1, dataset 2); // new conspiracy .Senderer (renderer); // new chart = new GeFree chart (plot); Chart.removeLegend (); ChartPanel CP = New ChartPanel (Chart); This.add (cp); }    

No comments:

Post a Comment