Page 1 of 1

Stacked BarChart - data not lining up?

Posted: Tue May 15, 2007 10:48 am
by 9534808
Hi there - I have a stacked barchart and am finding that I'm having difficulty getting my data to line up correctly without lots of programming work on my part. I'm thinking I must be doing something obviously wrong and am after a few pointers.

Essentialy I want to have bars for: Jan Wk1, Jan Wk2, Jan Wk3, Jan Target, Feb Wk1 .... Feb Target etc.

For each bar I have 4 stacked values, Sales Complete, Sales In Progress, Sales Remaining, Target. The target should be zero for each of the weeks as there aren't any weekly targets but have a number for the "Month" Target bar. Hopefully you can visualise that.

Based on the avbove, my data is calculated in memory and I output to each of the series - the target series is Null for each of the WkX bars and has a positive value for the Monthly target bar (so you can easily see how close sales were to the targets) so I loop through each of my months and do (in pseudo code):

for each week targetSeries addNull (week name).
targetSeries add (month target), (month name + ' Target')

(I repeat the above for 4 months - e.g. a Quarter).

I wasn't expecting to have to write out the null values above but I found that if I didn't do this - my target values didn't line up for each bar.

Next I need to write out the actual sales - so I do something similar

for each week actualSalesSeries add week sales, week name

However this is where I hit the problem - I was kind of expecting to be able to write these values in any order, and if I provided the same label name then the items would just go into the correct columns. This doesn't seem to the be case - I seem to need to sort my data so that I process Wk1 data first, then Wk2 data etc.

What complicates this even more, is that the bars don't seem to sum the data in the series for me - I have to calculate my total and do a single "Add" call for each month (I was kind of hoping I didn't need to do this - again code solves this but its getting more complicated as I have to have a hashtable to collect up the values).

Finally what seems to make this even more difficult, is that I am finding (having resolved the above problems in my own code) - that if I then go to Add data for my second series - if I am missing "pendingSales" for a particular week - if I don't write a value out for that week the values for the next week (say week 3) will go into the week 2 position which didn't have any data.

Is this right? Do I need to work out my data dimensions and then rigidly stick to them (e.g. if its a 4 x 16 table of data, I have to ADD all 16 values for a particular series - otherwise I get off by X errors).

If this is the case - why do you need to specify a "label" for each data ADD - it seems superfluous - as it just seems to over-write the previous label?

I'm thinking that I'm doing something wrong - or missing some obvious solution so I would appreciate any tips or examples (in VB is fine - I will convert it).

Tim

Posted: Tue May 15, 2007 11:18 am
by narcis
Hi Tim,
However this is where I hit the problem - I was kind of expecting to be able to write these values in any order, and if I provided the same label name then the items would just go into the correct columns. This doesn't seem to the be case - I seem to need to sort my data so that I process Wk1 data first, then Wk2 data etc.
You may need to set XValues ValueList order as by default it is ascending. You can see how to do that here.
What complicates this even more, is that the bars don't seem to sum the data in the series for me - I have to calculate my total and do a single "Add" call for each month (I was kind of hoping I didn't need to do this - again code solves this but its getting more complicated as I have to have a hashtable to collect up the values).
It's difficult guessing which is the exact problem without being able to reproduce it here but you may be interested in checking Add function. You'll find more information about functions at the tutorials and features demo available at TeeChart's program group.
Finally what seems to make this even more difficult, is that I am finding (having resolved the above problems in my own code) - that if I then go to Add data for my second series - if I am missing "pendingSales" for a particular week - if I don't write a value out for that week the values for the next week (say week 3) will go into the week 2 position which didn't have any data.

I can think of 2 options here:

1. Add null values to the series where there's no existing value.
2. Use AddXY to specify at which X value each series point should be plotted.

Is this right? Do I need to work out my data dimensions and then rigidly stick to them (e.g. if its a 4 x 16 table of data, I have to ADD all 16 values for a particular series - otherwise I get off by X errors).
I don't think so, I may try using option 2 above.
I'm thinking that I'm doing something wrong - or missing some obvious solution so I would appreciate any tips or examples (in VB is fine - I will convert it).
It is difficult guessing which can the problems be without being able to reproduce them here. Could you please try my suggestions and if they don't help arrange a simple example project we can run "as-is" to reproduce the problems here?

You can either post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.

Thanks in advance.

Posted: Tue May 15, 2007 4:35 pm
by 9534808
Thanks for the swift reply.
I can think of 2 options here:

1. Add null values to the series where there's no existing value.
2. Use AddXY to specify at which X value each series point should be plotted.
The pointer to option #2 was an interesting one, I gave it a go but still found that without values for EVERY x,y coordinate in every series that the bars float around in strange ways. I also find that the XY graph doesn't look as good as a straight Bar graph with values - as you have to specify a 0 value and there is no concept of null so you get little flat bars that don't look so great.

I've worked around it in code for now, as it looks like it just works that way - however I think that its not as helpful as it could be.

To me it would make more sense if you could define all of the X value bar items and then for each series specify the Y value for any defined bars you choose to enter a value for (in any order). I think you were thinking that XY would do this - but it doesn't seem to.

Anyway - thanks for the help.

Tim

Posted: Wed May 16, 2007 7:39 am
by narcis
Hi Tim,

Then, you may want to try combining AddXY with AddNullXY where you don't want any value to be plotted.