-2

i am searching for any API that can be used for calculating the amount of area under a LineChart in JAVAFX. Do you know any?

omidXxX
  • 147
  • 1
  • 1
  • 9
  • 2
    Apply the [*Trapezoidal rule*](https://en.wikipedia.org/wiki/Trapezoidal_rule) to your `XYChart.Data`. – trashgod Sep 23 '17 at 16:33

1 Answers1

1

I don't know about an API, but it can be done manually. Calculating integrals in code is not that difficult, but the problem is that you don't have a function but rather a collection of points.

A good option is to use Simpson's rule for integration. Recently I came accross this formula:

simpson's rule

You can implement it to calculate your area, you just need a set of coordinates which you can get from you graph.

EDIT

I missed something about your question: you refred to a line chart. You see, the Simpson's rule uses slices which makes it really good for every function, including polynomial functions. But when working only with line charts, it would probably be faster working with trapezoids since they use straight lines. So you could use the trapezoidal rule instead, but odds are there isn't much difference.

Thanks to @trashgod for commenting.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
tomtzook
  • 539
  • 2
  • 6