Assign values to x,y axes in chart Spline.
· Hello,
I am working on simple handover process from one mobile station to other. I got three proposed results service disruption time, network entry time, connection set up time. I also have the result of these three as by using some conventional way and got improved these three delay results by proposed way. Results are store in textboxes. Now i want to show graphically. E.g. I want to show conventional service disruption time on x axis and proposed service disruption time on y axis or vice versa. Let suppose I want to have a scale on axes from 1 to 3000 milliseconds. Then I want to show how purposed scheme is better. I am using VB.Net 2008
Please guide me how to do this. I have created chart. I also studied MS chart for windows forms samples environment. Also applied different chart properties like titles, series and others, But I am not able to make x and y axes scales. How to get values on the axes and how to generate graph?
Also tried this code
chartSDT.ChartAreas("0").AxisY.Maximum = 1000 'chartSDT in name of chart for service disruption time
The i am getting this error
A chart element with the name '0' could not be found in the 'ChartAreaCollection'.
i also tried using ChartAreas(Default") but i am getting same idea.
I don’t get what for this chartAreas value in parenthesis is used. Please let me know..
Thanks
Naina
Answers
- Your code is essentially correct. The example uses the following:
The chart areas are regions of the chart picture where a chart can be displayed. The default area is the whole picture. Are you creating your areas in the designer? Select the chart, select Chart Areas in the Properties list, and open the ChartArea collection editor. Select each area in turn and note the Name property. If there is only one area, this is Default, but if you have defined multiple areas then the name will be different - probably describing the chart in that area. This is the name you use when setting the axis scales for the chart that will appear in that area.' Set manual minimum and maximum values. Chart1.ChartAreas("Default").AxisY.Minimum = 10 Chart1.ChartAreas("Default").AxisY.Maximum = 1000- Marked As Answer byMartin Xie - MSFTMSFT, ModeratorWednesday, November 04, 2009 2:59 AM
- Proposed As Answer byMaDFroG20091013 Monday, November 02, 2009 10:32 AM
What was the name that you saw when you dropped down that box on the ChartAreas error line? What is the name that you see when you access the Chart Areas in the properties list at design time. Are you creating or modifying the chart areas at all in your code (other than the error line you have mentioned)?
For the series, I can't see that you have created the series "Nothing". The series must be created and added to the chart before you try to use it.
Your code should look something like this:Dim Series1 As New Series() Dim Series2 As New Series() ' Add data points to the two series Dim random As New Random() Dim pointIndex As Integer For pointIndex = 0 To 9 Series1.Points.AddY(random.Next(45, 95)) Series2.Points.AddY(random.Next(5, 75)) Next pointIndex ' Set series chart type Series1.ChartType = SeriesChartType.Line Series2.ChartType = SeriesChartType.Spline ' Set point labels Series1.IsValueShownAsLabel = True Series2.IsValueShownAsLabel = True 'Set series names Series1.Name = "Current" Series2.Name = "Proposed" ' Add both series to the chart Chart1.Series.Add(Series1) Chart1.Series.Add(series2)I would recommend you edit your post above to remove the additional data or the thread will become unmanageable.
- Proposed As Answer byMaDFroG20091013 Monday, November 02, 2009 10:33 AM
- Marked As Answer byMartin Xie - MSFTMSFT, ModeratorWednesday, November 04, 2009 2:59 AM
All Replies
- Your code is essentially correct. The example uses the following:
The chart areas are regions of the chart picture where a chart can be displayed. The default area is the whole picture. Are you creating your areas in the designer? Select the chart, select Chart Areas in the Properties list, and open the ChartArea collection editor. Select each area in turn and note the Name property. If there is only one area, this is Default, but if you have defined multiple areas then the name will be different - probably describing the chart in that area. This is the name you use when setting the axis scales for the chart that will appear in that area.' Set manual minimum and maximum values. Chart1.ChartAreas("Default").AxisY.Minimum = 10 Chart1.ChartAreas("Default").AxisY.Maximum = 1000- Marked As Answer byMartin Xie - MSFTMSFT, ModeratorWednesday, November 04, 2009 2:59 AM
- Proposed As Answer byMaDFroG20091013 Monday, November 02, 2009 10:32 AM
Under the name property its "chartSDT". I tried it using instead of "defualt"but its not working.
can you please guide me how to do numbering of x,y axes..There is no numbering scale on x axis. But dont know how on y-axis it 2,4,6,8,12...while x-axis line is empty..
I want x-axis as 10,20,40,60,80...and so on...same is the case with y-axis. Then i have to generate points (X,y) eg, (2,10)..this way i want to genrate a graph..Please help me out..
Thanks
NainaWhat do you mean by 'not working'? Do you get the error message
" A chart element with the name 'chartSDT' could not be found in the 'ChartAreaCollection' "?
If so, do this:
When the error occurs, hover the mouse over 'ChartAreas' on the error line. There should be a highlighted popup with a + sign at the start. Click the + and move the cursor onto the new line that appears. A table will drop down. Scroll down the table to Name. The Name that appears in the right-hand coluumn is the name that you use instead of Default in the line:
chartSDT.ChartAreas("Default").AxisY.Maximum = 1000
If the problem is something else, you will need to describe what you are expecting to happen and what is actually happening, as well as what you have done so far to try and fix it.- Proposed As Answer byMaDFroG20091013 Monday, November 02, 2009 10:32 AM
Ya i get the same errror. Instead of default i used "proposed", "conventional", "nothing", "series1", and "series2"
But against every keyword i get the same error...A chart element with the name.....could not be found..
I followed your instruction but i am getting same error...
I am using so far sample code. If i am able to run this suceesfully then i can work on my own code..
code details...Imports System.Windows.Forms Imports System.Windows.Forms.DataVisualization.Charting 'Imports System.Data 'Imports System.Data.OleDb Public Class Graph Private Sub Graph_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim random As New Random() Dim pointIndex As Integer For pointIndex = 0 To 9 ChartSDT.Series("nothing").Points.AddY(random.Next(45, 95)) ChartSDT.Series("conventional").Points.AddY(random.Next(5, 75)) Next pointIndex ' Set series chart type ChartSDT.Series("Series1").ChartType = SeriesChartType.Line ChartSDT.Series("Series2").ChartType = SeriesChartType.Spline ' Set point labels ChartSDT.Series("Series1").IsValueShownAsLabel = True ChartSDT.Series("Series2").IsValueShownAsLabel = True ' Enable X axis margin ChartSDT.ChartAreas("Default").AxisX.IsMarginVisible = True ' Show as 3D ChartSDT.ChartAreas("Default").Area3DStyle.Enable3D = True End Sub Private Sub ExitGraph_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitGraph.Click Me.Close() End Sub Private Sub ChartSDT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChartSDT.Click End Sub End Class
on this line i get error ArgumentException was unhandled
A chart element with the name 'nothing' cannot be find in the 'SeriesCollection'
ChartSDT.Series("nothing").Points.AddY(random.Next(45, 95))
Some of details are here...This when i use the code with name "nothing"
- ChartSDT {System.Windows.Forms.DataVisualization.Charting.Chart} System.Windows.Forms.DataVisualization.Charting.Chart
- AccessibilityObject {System.Windows.Forms.DataVisualization.Charting.Utilities.ChartAccessibleObject} System.Windows.Forms.AccessibleObject
- System.Windows.Forms.DataVisualization.Charting.Utilities.ChartAccessibleObject {System.Windows.Forms.DataVisualization.Charting.Utilities.ChartAccessibleObject} System.Windows.Forms.DataVisualization.Charting.Utilities.ChartAccessibleObject
- Bounds {X = 240 Y = 70 Width = 798 Height = 663} System.Drawing.Rectangle
Bottom 733 Integer
- Empty {X = 0 Y = 0 Width = 0 Height = 0} System.Drawing.Rectangle
Bottom 0 Integer
- Empty {X = 0 Y = 0 Width = 0 Height = 0} System.Drawing.Rectangle
Bottom 0 Integer
- Empty {X = 0 Y = 0 Width = 0 Height = 0} System.Drawing.Rectangle
Bottom 0 Integer
- Empty {X = 0 Y = 0 Width = 0 Height = 0} System.Drawing.Rectangle
Bottom 0 Integer
- Empty {X = 0 Y = 0 Width = 0 Height = 0} System.Drawing.Rectangle
Bottom 0 Integer
- Empty {X = 0 Y = 0 Width = 0 Height = 0} System.Drawing.Rectangle
Bottom 0 Integer
- Empty {X = 0 Y = 0 Width = 0 Height = 0} System.Drawing.Rectangle
Bottom 0 Integer
- Empty {X = 0 Y = 0 Width = 0 Height = 0} System.Drawing.Rectangle
Bottom 0 Integer
- Empty {X = 0 Y = 0 Width = 0 Height = 0} System.Drawing.Rectangle
Bottom 0 Integer
- Empty {X = 0 Y = 0 Width = 0 Height = 0} System.Drawing.Rectangle
+ MousePosition {X = 104 Y = 634} System.Drawing.Point
Name "ChartSDT" String
+ Padding {System.Windows.Forms.Padding} System.Windows.Forms.Padding
Palette None {0} System.Windows.Forms.DataVisualization.Charting.ChartColorPalette
PaletteCustomColors {Length=0} System.Drawing.Color()
+ Parent {Handover.Graph} System.Windows.Forms.Control
Please guide me. I am in big trouble. My thesis is stuck because of charts..
Thanks
Naina- Edited byNainaRonak Friday, October 30, 2009 1:08 PMUnmanagebale post
What was the name that you saw when you dropped down that box on the ChartAreas error line? What is the name that you see when you access the Chart Areas in the properties list at design time. Are you creating or modifying the chart areas at all in your code (other than the error line you have mentioned)?
For the series, I can't see that you have created the series "Nothing". The series must be created and added to the chart before you try to use it.
Your code should look something like this:Dim Series1 As New Series() Dim Series2 As New Series() ' Add data points to the two series Dim random As New Random() Dim pointIndex As Integer For pointIndex = 0 To 9 Series1.Points.AddY(random.Next(45, 95)) Series2.Points.AddY(random.Next(5, 75)) Next pointIndex ' Set series chart type Series1.ChartType = SeriesChartType.Line Series2.ChartType = SeriesChartType.Spline ' Set point labels Series1.IsValueShownAsLabel = True Series2.IsValueShownAsLabel = True 'Set series names Series1.Name = "Current" Series2.Name = "Proposed" ' Add both series to the chart Chart1.Series.Add(Series1) Chart1.Series.Add(series2)I would recommend you edit your post above to remove the additional data or the thread will become unmanageable.
- Proposed As Answer byMaDFroG20091013 Monday, November 02, 2009 10:33 AM
- Marked As Answer byMartin Xie - MSFTMSFT, ModeratorWednesday, November 04, 2009 2:59 AM
I got it now..Names are 0 and 1. Here is the correct code. Its working now..Now i have to modifly according to my requirement..Hope i wont get any issue...
Dim random As New Random()
Dim pointIndex As Integer
For pointIndex = 0 To 9
ChartSDT.Series(0).Points.AddY(random.Next(45, 95))
ChartSDT.Series(1).Points.AddY(random.Next(5, 75))
Next pointIndex' Set series chart type
ChartSDT.Series(0).ChartType = SeriesChartType.Line
ChartSDT.Series(1).ChartType = SeriesChartType.Spline' Set point labels
ChartSDT.Series(0).IsValueShownAsLabel = True
ChartSDT.Series(1).IsValueShownAsLabel = True' Enable X axis margin
ChartSDT.ChartAreas(0).AxisX.IsMarginVisible = True' Show as 3D
ChartSDT.ChartAreas(0).Area3DStyle.Enable3D = True
Thanks for your help..I will post further here if any problem arise..Thanks Acmar
Naina- All collections of named objets in the chart are identifiable either by their index or their name. If you wish to use the name you have to ensure that you have identified the names and have spelled them correctly. If you wish to use the index then you only have to ensure that you keep track of the order in which you add the objects into the collection, because it is the order of adding that determines the index number that will be used for the object.
- Proposed As Answer byMaDFroG20091013 Monday, November 02, 2009 10:33 AM
- Thanks. Under the chart series collection editior i got two member (0) Proposed and (1) Conventional. But i i get an error when i use name instead of index
Cant understand the issue.. - What's the error message?
I am not able to get how to label x-axis as milliseconds like 10 20 30 50 60 70 80 . It shows just 1 2 3 4 5 dont know how to change it..same is the case with y-Axis how to change its lables. Please guide me with some code hints.
Thanks
Naina- You can set your axis details with code like this:
Chart1.ChartAreas("Proposed").AxisY.Minimum = 0 Chart1.ChartAreas("Proposed").AxisY.Maximum = 5 Chart1.ChartAreas("Proposed").AxisY.Interval = 1 Chart1.ChartAreas("Proposed").AxisY.TextOrientation = DataVisualization.Charting.TextOrientation.Rotated270 Chart1.ChartAreas("Proposed").AxisY.Title = "Incidents" Chart1.ChartAreas("Proposed").AxisX.Minimum = 0 Chart1.ChartAreas("Proposed").AxisX.Maximum = 100 Chart1.ChartAreas("Proposed").AxisX.Interval = 10 Chart1.ChartAreas("Proposed").AxisY.TextOrientation = DataVisualization.Charting.TextOrientation.Horizontal Chart1.ChartAreas("Proposed").AxisY.Title = "Milliseconds" Thanks Acmar this code was helpful for me. I am finally getting to learn charts. This code helped me how to change axes values from the chartArea collection editor. That way i don’t need to write code for this. Chart properties is very vast... But i tried your code don’t know why it’s not working when i use "proposed" or "conventional" instead i have to use x and y indexes..May be i changed some setting while exploring chart property..But no worries i can do now label axes from chart control according to my requirements.
One more question can you please guide me do i need to set milliseconds on y-axis and the other one eg speed on x-axis. I think there is no restriction?
As my chart should be for proposed and conventional scheme (these two are in milliseconds) and i want to compare each on against speed or bandwidth or anyone else parameter. But both schemes should be on same chart..
Can you please suggest me for this..Thanks for helping
Naina
- In that case you do not have two chart areas, so all your references can be to ChartAreas(0). What you have is one chart area and two series. So in the Series (Collection) editor in the chart properties editor, select Add and add a second series. These series would be labelled Proposed and Convetional, not the Chart Areas.
The code example I posted last week shows how you use the two series to set chart type, how the labels are shown, and other features of the series (or you can do it all from the designer). Then add values (X,Y pairs) for each series separately, using either the index (0,1) or the series names. Thanks. Under the ChartArea Collectin Editor, I have member (0)ChartAreaSDT only. You mean to say I have to add another member here? If so, I did this experiment. It shows separate blank area just below the graph I have; I have kept only one member.
Yes under the Series Collection Editor I already have added two members..(0) Proposed and (1) Conventional
I have a handover.vb page..where I generate some results in text boxes...
E.g i have textbox name=sdTimep (this is the value I want for conventional) and textbox name=sdTime (this is the value I want on proposed for the chart). How can I use those text box values on the graph.vb page (this is the page where I have charts).
I know passing value from text boxes from one page to another but don’t know how to do text box to graph passing values..?
I got the generate graph button named "GenerateGraph" on handover.vb. After getting results on handover.vb page, when I click on "GenerateGraph" button on Handover.vb it takes me to "graph.vb"
E.g. I want conventional and proposed values of textboxes on y-axis and throughput on x-axis
Value points should be like pair (x,y) and first I have to do x for conventional vs. y throughput and get a graph line with different point value generated.
Then same process for x as proposed and y taking as same throughput and generate another graph line on same chart.
i.e. proposed vs. throughput and
Conventional vs. throughput
Hopefully I am able to narrate the scenario
Thanks
Naina
- Your original arrangement was correct - one chart area and two series. The chart area name doesn't matter (as there is only one) so you can reference it as ChartAreas(0).
To add data to your series you use the Point.Add(X,Y) method of the Series object. For instance:
Chart1.Series("Proposed").Points.AddXY(XValue,Val(sdTimeP.Text)) Chart1.Series("Conventional").Points.AddXY(XValue,Val(sdTime.Text))
If you are adding values in sequence you can simplify it slightly and use the AddY method - you haven't indicated how the X values are being calculated.. I did like this to get rough idea and added maximum and min values for axes from control and their intervals.
'Conventional Service Disruption Time
ChartSDT.Series(1).Points.AddXY(25, 457)
'Proposed Service Disruption Time
ChartSDT.Series(0).Points.AddXY(50, 10)
'Conventional Network Entry Time
ChartNET.Series(1).Points.AddXY(50, 3107)
'Proposed Network Entry Time
ChartNET.Series(0).Points.AddXY(50, 99) '1
'Conventional Connection Set-up Time
ChartCST.Series(1).Points.AddXY(50, 232)
'Proposed Connection Set-up Time
ChartCST.Series(0).Points.AddXY(50, 4705)
I have to take speed(in bits) on x-axis..It can be random. Yet to explore how to do that? Any suggestions?
I tried your above code...like this
Dim xvalue As Object
Dim sdTimep As DoubleChartSDT.Series(0).Points.AddXY(XValue, Val(sdTimeP.Text)) 'its for the chart for Sevice disruption time
But it shows error..."Text is not a member of double"...Even i tried other data types, string etc..Do i need conversion?
THe code you mentioned will just show one entry on the graph. What i want like i run the simulation few time and that values should be stored for the chart automatically and when i run the chart it should chart according to those values. Is that possible? or do i need some data data storage like excel etc..or can it be possible witout it..- Where exactly are your X values and your Y values stored? I used sdTimeP.Text because you have indicated that sdTimeP was a text box. But I don't know how you have got the values out of the text boxes and put them into variables.
For instance, if your proposed X Y value pairs are stored in pX() and pY() then
For I As Integer = 0 To pX.Count - 1
Chart1.Series("Proposed").Points.AddXY(pX(I), pY(I))
Next I
and if your conventional X Y value pairs are stored in cX() and cY() then
For I As Integer = 0 To cX.Count - 1
Chart1.Series("Conventional").Points.AddXY(cX(I), cY(I))
Next I
so it really depends on how you have stored the values you want to plot. X- values are random ----generate on my own ..No. of Neighboring base stations. While as Y-Axis is concered i run some simple simulation on handover.vb page for mobile handover and then on the same page i calculate different parameters for this handover like service disruption time,network entry time and connection set-up time, radio layer latency etc.. these results are shown by text boxes on the same page..ANd i want these results on y-axis..like once i run handover and get some results and these should be saved for graph..then again when i run the application it should be store for graph..then i want it for graph like few entries at least 8 values for x-axis.. i want to do it dynamically...but so for i did it manually recording each simulation result and using it like this....
Conventional Service Disruption Time
ChartSDT.Series(1).Points.AddXY(1, 542)
ChartSDT.Series(1).Points.AddXY(2, 540)
ChartSDT.Series(1).Points.AddXY(3, 363)
ChartSDT.Series(1).Points.AddXY(4, 514)
ChartSDT.Series(1).Points.AddXY(5, 485)
ChartSDT.Series(1).Points.AddXY(6, 506)
ChartSDT.Series(1).Points.AddXY(7, 516)
ChartSDT.Series(1).Points.AddXY(8, 523)
ChartSDT.Series(1).Points.AddXY(9, 332)
ChartSDT.Series(1).Points.AddXY(10, 519)'Proposed Service Disruption Time
ChartSDT.Series(0).Points.AddXY(1, 23)
ChartSDT.Series(0).Points.AddXY(2, 26)
ChartSDT.Series(0).Points.AddXY(3, 17)
ChartSDT.Series(0).Points.AddXY(4, 33)
ChartSDT.Series(0).Points.AddXY(5, 105)
ChartSDT.Series(0).Points.AddXY(6, 23)
ChartSDT.Series(0).Points.AddXY(7, 25)
ChartSDT.Series(0).Points.AddXY(8, 20)
ChartSDT.Series(0).Points.AddXY(9, 9)
ChartSDT.Series(0).Points.AddXY(10, 24)'Conventional Network Entry Time
ChartNET.Series(1).Points.AddXY(1, 204)
ChartNET.Series(1).Points.AddXY(2, 507)
ChartNET.Series(1).Points.AddXY(3, 143)
ChartNET.Series(1).Points.AddXY(4, 77)
ChartNET.Series(1).Points.AddXY(5, 383)
ChartNET.Series(1).Points.AddXY(6, 449)
ChartNET.Series(1).Points.AddXY(7, 357)
ChartNET.Series(1).Points.AddXY(8, 807)
ChartNET.Series(1).Points.AddXY(9, 855)
ChartNET.Series(1).Points.AddXY(10, 299)'Proposed Network Entry Time
ChartNET.Series(0).Points.AddXY(1, 86)
ChartNET.Series(0).Points.AddXY(2, 119)
ChartNET.Series(0).Points.AddXY(3, 34)
ChartNET.Series(0).Points.AddXY(4, 2)
ChartNET.Series(0).Points.AddXY(5, 175)
ChartNET.Series(0).Points.AddXY(6, 237)
ChartNET.Series(0).Points.AddXY(7, 176)
ChartNET.Series(0).Points.AddXY(8, 148)
ChartNET.Series(0).Points.AddXY(9, 818)
ChartNET.Series(0).Points.AddXY(10, 236)'Conventional Connection Set-up Time
ChartCST.Series(1).Points.AddXY(1, 507)
ChartCST.Series(1).Points.AddXY(2, 826)
ChartCST.Series(1).Points.AddXY(3, 719)
ChartCST.Series(1).Points.AddXY(4, 541)
ChartCST.Series(1).Points.AddXY(5, 435)
ChartCST.Series(1).Points.AddXY(6, 446)
ChartCST.Series(1).Points.AddXY(7, 269)
ChartCST.Series(1).Points.AddXY(8, 650)
ChartCST.Series(1).Points.AddXY(9, 790)
ChartCST.Series(1).Points.AddXY(10, 679)'Proposed Connection Set-up Time
ChartCST.Series(0).Points.AddXY(1, 303)
ChartCST.Series(0).Points.AddXY(2, 296)
ChartCST.Series(0).Points.AddXY(3, 577)
ChartCST.Series(0).Points.AddXY(4, 486)
ChartCST.Series(0).Points.AddXY(5, 80)
ChartCST.Series(0).Points.AddXY(6, 285)
ChartCST.Series(0).Points.AddXY(7, 77)
ChartCST.Series(0).Points.AddXY(8, 139)
ChartCST.Series(0).Points.AddXY(9, 103)
ChartCST.Series(0).Points.AddXY(10, 110)
And i am able to generate the graph(column for proposed/conventional)..But i am looking for some data binding..automatically store value for graph..Dont know how to do that..Try to learn that..
Thanks alot for your help
Naina- It seems that your X values are sequential, not random. In that case you can either generate them yourself (as above), or simply use the AddY method to create Y values for sequential X points.
I don't quite understand how you are creating those sets - it seems to me you should have 6 series, not two, or perhaps 3 chart areas of two series each. However, your point now seems to be the source for your data, and I must admit I don't understand your description of how you are getting this data.
But for your above example you are going to need 6 integer arrays of 10 elements each, and if you get these arrays properly populated you won't have any problem filling in the graph. If you have queries about how to create, populate, store and retrieve these arrays then you can start a new thread on that specific problem. Yes you can say x values are sequential.
Yes i got 3 charts on graph.vb page chartSDT, chartNET, chartCST each with conventional and proposed series
I am getting the values from handover.vb page for y-axis. Right now i dont have problem in generating the charts, but i want to manage in a more better and effieient accurate way
Anyways..
Thanks alot i will start another thread. I appriciate your help.
Naina


