How do I create a graph from calculations?

I have an index of documents containing the following information:

- id
- begin_event (keyword)
- end_event (keyword)
- duration (float)

And here's an example of some of those docs as comma-delimited lines:

101, CALC_FOO_BEGIN, CALC_FOO_END, 5.3

102, CALC_BAR_BEGIN, CALC_BAR_END, 2.7

103, CALC_FOO_BEGIN, CALC_FOO_END, 4.5

104, CALC_BAR_BEGIN, CALC_BAR_END, 3.2

Now what I'd like to do is create a chart of all the time spent with the following formula:

SUM(CALC_FOO_BEGIN/END event durations) - SUM(CALC_BAR_BEGIN/END event durations)

Although I've been successful creating charts for CALC_FOO_BEGIN/END duration sums and CALC_BAR_BEGIN/END duration sums, I don't know how to calculate the differences as shown above.

Any tips. Still a newbie but trying hard!

Thanks,

John.