1,105,594 Community Members

additional text on chart x axis

Member Avatar
Lethugs
Junior Poster
131 posts since Nov 2012
Reputation Points: 8 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 0 [?]
 
0
 

hi
Im using chart to display data in VS 2010, its working properly with this code...

Chart1.Series(0).Name = "Days Used"
Chart1.Series(0).Color =Color.Red
Chart1.Series(0).XValueMember ="Account Name"
Chart1.Series(0).YValueMembers ="Days Used"
Chart1.Series(0).IsValueShownAsLabel =True

my x&yvaluemembers value came from sql server database. The "Account Name" And "Days Used" are alias of my database column from my select statement. How can i add additional label to my x-axis? I just need to display the name of account then indicate if its the original user, something like:

Mike (original User)
John (second User)

I tried adding string but i failed, the chart wont display records anymore because it will no longer match with the database column alias. I also used customlabel but gives me an error

Dim c As New CustomLabel
c ="Account Name"+"orig User"
Chart1.ChartAreas(0).AxisX.CustomLabels.Add(c)

Error: Value of string cannot be converted to 'System.Windows.Forms.DataVisualization.Charting.CustomLabel

Thanks for helping

Member Avatar
tinstaafl
Postaholic
2,012 posts since Jun 2010
Reputation Points: 559 [?]
Q&As Helped to Solve: 402 [?]
Skill Endorsements: 35 [?]
 
0
 

try this, c.Text ="Account Name"+"orig User".

Member Avatar
Lethugs
Junior Poster
131 posts since Nov 2012
Reputation Points: 8 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 0 [?]
 
0
 

It only changes the position of my chart, and labels are gone in my x axis

Member Avatar
TnTinMN
Practically a Master Poster
640 posts since Jun 2012
Reputation Points: 418 [?]
Q&As Helped to Solve: 152 [?]
Skill Endorsements: 16 [?]
 
0
 

How about just adding a title?

   Dim sometitle As New Title()
   With sometitle
      .Text = "Fred"
      .IsDockedInsideChartArea = True
      .Docking = Docking.Bottom
      .Alignment = ContentAlignment.MiddleCenter
   End With
   Chart1.Titles.Add(sometitle)
Member Avatar
Lethugs
Junior Poster
131 posts since Nov 2012
Reputation Points: 8 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 0 [?]
 
0
 

I need to diplay it along with the Account Name or some below it, there a lot of Account Name based on the records in my database, I just need to indicate if its the original user thats why im trying to add extra text.

How will i do it?

Thanks for your effort

Member Avatar
tinstaafl
Postaholic
2,012 posts since Jun 2010
Reputation Points: 559 [?]
Q&As Helped to Solve: 402 [?]
Skill Endorsements: 35 [?]
 
0
 

in the Add method of the customlabels, the overloads allow you to set the postion of the label and set the text, it's something like this, Chart1.ChartAreas(0).AxisX.CustomLabels.Add(fromPosition as Double, toPosition as Double, Text as String).

Member Avatar
Lethugs
Junior Poster
131 posts since Nov 2012
Reputation Points: 8 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 0 [?]
 
0
 

in the Add method of the customlabels, the overloads allow you to set the postion of the label and set the text, it's something like this, Chart1.ChartAreas(0).AxisX.CustomLabels.Add(fromPosition as Double, toPosition as Double, Text as String).

Does this work even if my xvaluemember varies in number of "Account Name"? or do i need to add that code depending on the number of x member?

Thanks again

Member Avatar
tinstaafl
Postaholic
2,012 posts since Jun 2010
Reputation Points: 559 [?]
Q&As Helped to Solve: 402 [?]
Skill Endorsements: 35 [?]
 
0
 

I don't have a lot of experience with charts, But from what I gather, you can basically add text to each position, just make to and from the same. It might get kind of complicated building the text in the statement, you might want to build it in a string variable first. It shouldn't be too difficult to iterate through the positions have a dictionary of name, type pairs to compare the xvaluemember against, and set the string from that. of course without the actual chart and data, all this is speculation :)

I came across something else that might do the trick, the striplines collection. Each item has it's own text property. You might be able to so something with that.

Member Avatar
Lethugs
Junior Poster
131 posts since Nov 2012
Reputation Points: 8 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 0 [?]
 
0
 

I understand, thanks for the help anyway

maybe someone out there could still help me

Member Avatar
TnTinMN
Practically a Master Poster
640 posts since Jun 2012
Reputation Points: 418 [?]
Q&As Helped to Solve: 152 [?]
Skill Endorsements: 16 [?]
 
0
 

Ok, I misunderstood what you were trying to accomplish.

You can add a new column to the source datatable (assuming the datasource is a table) to hold the computed label. Then use this new column as your XValueMember. Depending on the complexity of the logic, you may be able to use an DataColumn Expression to automatically compute the new string. Worse case is to loop through the rows and set the new value.

Member Avatar
Lethugs
Junior Poster
131 posts since Nov 2012
Reputation Points: 8 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 0 [?]
 
0
 

I find it hard to do it maybe because of the complexity of my code. Thanks for your help and support.

Member Avatar
TnTinMN
Practically a Master Poster
640 posts since Jun 2012
Reputation Points: 418 [?]
Q&As Helped to Solve: 152 [?]
Skill Endorsements: 16 [?]
 
0
 

There is nothing hard about adding a column to a datatable. The syntaX is

DataTableVariable.Columns.Add("New Column Name", GetType(String))

But if you prefer to give up on it, oh well.

Member Avatar
Lethugs
Junior Poster
131 posts since Nov 2012
Reputation Points: 8 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 0 [?]
 
0
 

I find it hard to do it maybe because of the complexity of my code. Thanks for your help and support.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: