|
Stacked Bars + SetXData |
Posted by Zev Toledano on Feb-27-2011 20:16 |
|
I am having a tricky problem with combining multiple Bar datasets and setXData.
Let's use an example: Say the xaxis is a linear (or even a date scale) from 1-1000000 with scattered values like 12345.678 and 987654.55.
Now some of the x values may have two or more values, which I would like to stack as a stacked bar. So for example, if the xvalue '987654.55' has 5 records, I need 5 stacked datasets.
Each dataset would probably have a different set of xvalues. I don't know how many values there will be per set or which.
From what I understand:
-I HAVE to use setXData for this - I cant create xlabels for every possible xvalue AND have it laid out linearly across the xaxis.
-I can't create a predefined list of values based on the xaxis full range of 1-1000000 with all decimal values in between and use this for setXData - too big.
-I can only define setXData at the layer level, not the dataset level. Here is my biggest problem. If I had it at the dataset level all of this would go away.
I thought of collecting all possible x-positions from all the datasets and combining this into a big array. For example if the data was:
y, x
10, 123.55
20, 200.44
15, 123.55
So I would make an array of 3 points which I would use for all datasets, init the values to NoValue where appropriate, and setXData to (123.55, 200.44, 123.55) for the whole layer.
But I'm very worried that this is not scalable at all. What if we are talking about 1000s of points and hundreds of sets? Then for each dataset I would have to give the graph a combined set of 1000000s of values, most of them NoValue, as well as setXData with an array of 1000000s of values.
There must be a better way to do this. Any ideas? |
Re: Stacked Bars + SetXData |
Posted by Zev Toledano on Feb-27-2011 22:50 |
|
I tried writing code for my above idea and saw that it's not going to work at all. If I setXData on stacked bars, it will only stack the points that are in the same position in the array, regardless of the SetXData position. So if I use SetXData(1,2,1) it won't stack the first and last values into a single stacked bar. Is this correct or am I doing something wrong?
So now I'm really stuck. Help?
The way I figure it I have to somehow build a unique+indexed list of all possible xvalues and use this for the xdata, then separate each duplicate xvalue that I find into a different dataset, then map each value in each dataset to the correct position in the array. This is also messy, and also a lot of code, and also it's going to be slow with large amounts of data. |
Re: Stacked Bars + SetXData |
Posted by Peter Kwan on Feb-28-2011 14:07 |
|
Hi Zev,
I am worry your data simply are not suitable for display using a stacked bar chart.
Note that a bar has a width in additional to a height. Let's say the bar width is 10 pixels, and your chart plot area is 1000 pixels wide, you should only have around 100 bars. If you have "all possible values from 0 to 1000000" (which is infinitely large), then how wide should each bar be?
Also, if your plot area only has 1000 pixels wide, the maximum number of bars you can see is 1000 (with each bar 1 pixel wide). If you have more than 1000 bars, but they do not stack (because their x-coordinates can be "all possible values from 0 to 1000000"), then they just overlap in the same pixel, and you can only see 1000 bars anyway. This is equivalent from dividing your data into 1000 groups (0 - 1000 = the first bar, 1000 - 2000 = the second bar, 2000 - 3000 the third bar, ...), and they for each bar, you just plot the peak value. If your data are from an SQL database, you can achieve the above easily by using an SQL "GROUP BY" query.
So a bar chart (and in particular a stacked bar chart) is normally only for "discrete x-coordinates", or for ranged data (that is each bar represents a range like 0 - 1000). It is because a bar has a finite width and it necessarily occupies a horizontal range.
I am not sure of the exact type of chart you want. If you just want to aggregate the data in the same x-position, you can use an SQL "GROUP BY" query. In this way, you do not need to write any additional code to aggregate the data. In general, data manipulation usually is not considered as the function of the chart, but is the function of the database.
You should use the chart for stacking only if you need to visually distinguish each stack. For example, if each stack needs to have a different color to represent different things, then you can use the chart to stack. In this case, you would need to use different data series for the different stacks as they are expected to represent different things.
Hope this can help.
Regards
Peter Kwan |
Re: Stacked Bars + SetXData |
Posted by Zev Toledano on Feb-28-2011 16:04 |
|
I didn't say that I have values in the database from 1-100000 but that the potential range is large and unknown. The actual values from the database may only result in 20 bars, but I don't know where they will be in the graph. A more practical example would be a datescale xaxis where the values can be on any second of the day from 1950 to 2010.
I thought about it some more today and I think I figured out a semi-complicated compromise I can live with involving searching for previous identical xaxis values and multiple layers...
What I was trying to show however, is that there is a need for setXData at the dataset level. Perhaps this scenario is obscure for you, but it's worth considering. Also, that setting setXData(1,2,1) does not result in stacked bars even though you now have two bars in the same place on the xaxis.
Both of these issues make it much harder to use bars on a continuous axis regardless of the range of the data. Just something to consider for a future version... |
|