1

I want to generate a bar graph based from user inputs but, I tried passing it from my main class to the class where I coded my graph and it doesn't work.

here's a part of my main class. It's were I will get the value.

public double computeE1() {
    double x1 = sFrame.s1;
    double x2 = tFrame.t1;
    double x3 = fFrame.f1;
    E1 = 5.278 + ((-0.172)*x1) + ((-0.197)*x2) + ((-0.191)*x3);
    return E1;  
}

and here's my JFreeChart class

public class BarChart extends ApplicationFrame {

GUImain gui; //main class


public BarChart(final String title)
{
    super(title);

    final CategoryDataset dataset = createDataset();
    final JFreeChart chart = createChart(dataset);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(500,270));
    setContentPane(chartPanel);
}


private CategoryDataset createDataset()
{
    double e1 = gui.E1;
    double e2 = gui.E2;
    double e3 = gui.E3;
    double e4 = gui.E4;

    DefaultCategoryDataset ds = new DefaultCategoryDataset();

    ds.addValue(e1, "asdas", null);
    ds.addValue(e2, "asdasda", null);
    ds.addValue(e3, "sar", null);
    ds.addValue(e4, "asda", null);

    return ds;      
}
chrisia
  • 11
  • 1
  • 3

1 Answers1

0

This can be very confusing when you are just learning Java. The trick is to have a "control" class, which controls and coordinates the other elements of the program (ie analytics, ui, etc). Your your case, I'd probably try to include the class that has your analytics into the class that you're using for your UI... Is the analytics class stateless? https://softwareengineering.stackexchange.com/.../whats-the-difference-between-stateful-and-stateless

Community
  • 1
  • 1
ControlAltDel
  • 33,923
  • 10
  • 53
  • 80
  • I have my main frame where I have a button that will call the graph. But I think the BarChart class couldn't read the values. I'm confused. – chrisia Sep 03 '14 at 15:43
  • my analytics class is inside my UI, if I understood you right. I'm so sorry, i'm new at this. – chrisia Sep 03 '14 at 15:46
  • The BarChart class shouldn't be reading anything... You should control (ie instantiate it, and call its methods) from your UI class – ControlAltDel Sep 03 '14 at 15:46