1

Working with Steema TeeChart graphs. (In particular objects: TChart, TChartSeries, TBarSeries, TLineSeries)

My task is to dynamically combine graphs when user selects some of the them, their values are added or subtracted based on XLabel value.

So this is what I get after selecting a couple of graphs and then deselecting them (which does the following:

  1. Sets Series with DefaultBar/LineSeries
  2. Adds values of selected graphs to the DefaultBar/LineSeries
  3. Subtracts values of deselected graphs from the DefaultBar/LineSeries)

Result (logically) has to be 0 for all XLabels

But here is what I get: graph

Same graph without marks graph2

Here are some of the values: Values

Can I somehow keep the actual values instead of rounded values (the ones represented on the graph), so that I will not have any rest after subtraction procedure?

I could do something like this to get rid of the rest (I know that the values will be big):

   //bad solution
   for Serie := 0 to Chart.SeriesCount - 1 do
     for YValue := 0 to Chart.Series[Serie].YValues.Count - 1 do
       if StrToFloat(FormatFloat('0.00', Chart.Series[Serie].YValue[YValue])) = 0 then
         Chart.Series[Serie].YValue[YValue] := 0;

But this is not a very great solution - not scalable.

Probably related:

When I select only 1 graph and deselect it, then all the values are 0, the problem occurs when multiple graphs are selected (addition occurs)

Boris Mocialov
  • 3,439
  • 2
  • 28
  • 55
  • 1
    If x=y then x-y=0. So I guess your x values are not the same. But then, I'm having to guess about both your code and your data since neither have been presented. Your problem surely has a solution, but I cannot discern what the problem is from the question as it stands now. – David Heffernan Jan 02 '14 at 12:26
  • Value does not change, it is rounded (well, changed) – Boris Mocialov Jan 02 '14 at 12:40
  • @DavidHeffernan values are the same, because when I select/deselect (add/subtract) graphs many times, values are still the same. I believe it is the rounding problem. Another thing is that the values examples I am shiwing, they are insignificant – Boris Mocialov Jan 02 '14 at 12:43
  • 1
    Why are you rounding? You did not show any code? Why not? Why are you concealing the details from us? Why am I having to guess? Again, let me make this very clear. If `x=y`, then `x-y=0`. So, if you are really doing `x-y`, then the only conclusion that can be drawn is that `x<>y`. But maybe you are not doing `x-y`. Maybe you are doing: `z := x + y; t = (z - x) - y;` Are you going to put us out of our misery and show some code so that we don't have to guess?! – David Heffernan Jan 02 '14 at 12:51
  • Apart from what has already been said, I believe this is essentially the same as temporarily storing data in a `TLabel` or `TEdit`. I wouldn't dare to rely that the TChart component doesn't do any "optimization" on the values you put into it, like rounding or truncating to smaller types and whatnot. I'd use the chart just for presentation, not for storing values. – Günther the Beautiful Jan 02 '14 at 13:07
  • @GünthertheBeautiful I am passing data in TBarSeries or TLineSeries. It should not get corrupted, i guess (but i am not very familiar with TeeChart components) – Boris Mocialov Jan 02 '14 at 14:22
  • @DavidHeffernan That is elementary arithmetics and it has to be right. I am not going to show any code for now, because I believe that the problem is with the component itself (rounding). Since it was not me who wrote that part of code, where graphs are represented individually, I cannot say (for now) if it is the rounding problem (that i think of) or not. And since I havent worked with TeeChart components before, I am asking if it is a common problem or not, thus trying to see if my assumption about rounding is right or not. I also believe that Günther the Beautiful has a point – Boris Mocialov Jan 02 '14 at 14:26
  • I am familiar with Teechart. I've used it for circa 15 years. It stores chart data as arrays of `Double`. There's no use blaming "rounding" generically. You need to be more precise. Don't expect a precise answer if you cannot give any details. Your question is vague and hence the tumbleweed. Is it a common problem for floating point arithmetic to be inexact? Yes. Is that the answer you are looking for? – David Heffernan Jan 02 '14 at 14:41
  • If you are sure there's a rounding problem, it shouldn't be difficult for you to prepare a simple example that demonstrates it. A SSCCE is always very helpful both for us to reproduce a problem (and try to find a solution for it) and for customers that usually find a mistake in their final/big/complicate project. – Yeray Jan 03 '14 at 09:05

0 Answers0