Jump to content
Software FX Community

Sample code to generate Stack in charts


kelmic1978

Recommended Posts

Hello

 I am new to chartfx, and going the tutorials provided by chartfx didn't help me much.

 I hope you guys can provide me some sample running code in VB.NET or point me some references in order to achieve what I need as show below.

[Prototype] 

formtextvalue1 = 2

formtextvalue2 = 5

sql = "select A,B,C from tableName"

 I want to put result A on the Y-axis, formtextvalue1 to 5 to being on my X-axis range, and values of B & C to be in the stack bar chart values.

Thanks in advance!

 [/End Prototype]

post-3100-13922400461347_thumb.jpg

Link to comment
Share on other sites

What do you mean by: "put result A on the Y-axis" ?

Aren't the stacked values (A and B) also plotted against the Y-Axis?

What is this "formtextvalue1 to 5"? Where does it come from?

Stacked charts are no different than any other chart and the data is passed in the same way (plenty of samples in the resource center). The only difference is how the data is plotted, is a stacked chart the each series is plotted on top of the previous series, making the values accumulate.

 So for example if you have a chart with two series, then you will have, for each point. a stacked bar with 2 sections, 1 for series 1 and 1 for series 2.

 By default,if you use DataBInding, each numeric column in your data source will become a series. For example if A,B and C are numeric:

"select A,B,C from tableName"

Will produce a chart with three series. This is three bar segments (colors) for each record in your resultset.

 

Link to comment
Share on other sites

Hello

Thanks for responding! Look below for my responses in italics. 

What do you mean by: "put result A on the Y-axis" ?

Aren't the stacked values (A and B) also plotted against the Y-Axis?

Response: You are right. Both A & B are to be plotted against Y-Axis. I just want to point that out, just in case.

What is this "formtextvalue1 to 5"? Where does it come from?

Response: formtextvalue1 is a form value i get from a dropdown list. Thus, my x-axis is supposed to be plotted with these 2 formtextvalue ranges.

Stacked charts are no different than any other chart and the data is passed in the same way (plenty of samples in the resource center). The only difference is how the data is plotted, is a stacked chart the each series is plotted on top of the previous series, making the values accumulate.

 So for example if you have a chart with two series, then you will have, for each point. a stacked bar with 2 sections, 1 for series 1 and 1 for series 2.

 By default,if you use DataBInding, each numeric column in your data source will become a series. For example if A,B and C are numeric:

"select A,B,C from tableName"

Will produce a chart with three series. This is three bar segments (colors) for each record in your resultset.

Response: Yes, I want A,B & C to be displayed as different the different bar segments, and they to correspond to the x-axis values i specifed.

post-3140-13922400476401_thumb.png

Link to comment
Share on other sites

Maybe I try to explain abit more? E.g. I have the following data to be plotted onto a stacked chart. 

TotalCost

Month

Dept

3  

1  

HR

2  

2  

IT

10  

2  

Sales

Thus, in my stacked chart, I want to have the months 1 & 2 on the X-axis. For month 1, my stacked chart will only have 1 color code, which is for HR, and will be to value 3. For month 2, my stacked chart will have 2 different color codes for "Total Cost" 2 & 10, and thus, in my legend box, I will have HR, IT & Sales different color codes for each.

I am having difficulties into having only 1 & 2 on my X-axis. What I am now having is 1,2 & a blank & X-axis "1" will have Y-axis value 3, "2" will have Y-axis value 2 & the blank will have Y-axis value 10.

Is this easier to understand what I want?

Link to comment
Share on other sites

Ok this is completely different. In this case the number of series is not determine by the number of columns but by the values of a specific column. In order for Chart FX to read this data it needs to be transformed to something like this:

Month HR   IT Sales

1 3   <null>  <null>

2 <null> 2 10

This type of transformation is commonly know as "crosstab" and you need to use the CrossTab data provider to feed data to your chart. There is a section in the programmer's guide and a sample program that shows you how to use the crosstab provider. You can also see it here:

http://support.softwarefx.com/OnlineDoc/CfxNet62/PG/crosstab.htm

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...