We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,001 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

additional text on chart x axis

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

3
Contributors
12
Replies
6 Days
Discussion Span
3 Months Ago
Last Updated
14
Views
Lethugs
Junior Poster
100 posts since Nov 2012
Reputation Points: 0
Solved Threads: 7
Skill Endorsements: 0

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

tinstaafl
Nearly a Posting Virtuoso
1,326 posts since Jun 2010
Reputation Points: 355
Solved Threads: 229
Skill Endorsements: 14

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

Lethugs
Junior Poster
100 posts since Nov 2012
Reputation Points: 0
Solved Threads: 7
Skill Endorsements: 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)
TnTinMN
Practically a Master Poster
640 posts since Jun 2012
Reputation Points: 418
Solved Threads: 148
Skill Endorsements: 13

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

Lethugs
Junior Poster
100 posts since Nov 2012
Reputation Points: 0
Solved Threads: 7
Skill Endorsements: 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).

tinstaafl
Nearly a Posting Virtuoso
1,326 posts since Jun 2010
Reputation Points: 355
Solved Threads: 229
Skill Endorsements: 14

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

Lethugs
Junior Poster
100 posts since Nov 2012
Reputation Points: 0
Solved Threads: 7
Skill Endorsements: 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.

tinstaafl
Nearly a Posting Virtuoso
1,326 posts since Jun 2010
Reputation Points: 355
Solved Threads: 229
Skill Endorsements: 14

I understand, thanks for the help anyway

maybe someone out there could still help me

Lethugs
Junior Poster
100 posts since Nov 2012
Reputation Points: 0
Solved Threads: 7
Skill Endorsements: 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.

TnTinMN
Practically a Master Poster
640 posts since Jun 2012
Reputation Points: 418
Solved Threads: 148
Skill Endorsements: 13

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

Lethugs
Junior Poster
100 posts since Nov 2012
Reputation Points: 0
Solved Threads: 7
Skill Endorsements: 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.

TnTinMN
Practically a Master Poster
640 posts since Jun 2012
Reputation Points: 418
Solved Threads: 148
Skill Endorsements: 13

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

Lethugs
Junior Poster
100 posts since Nov 2012
Reputation Points: 0
Solved Threads: 7
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0947 seconds using 2.69MB