1.11M Members

additional text on chart x axis

 
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

 
0
 

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

 
0
 

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

 
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)
 
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

 
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).

 
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

 
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.

 
0
 

I understand, thanks for the help anyway

maybe someone out there could still help me

 
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.

 
0
 

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

 
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.

 
0
 

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

Question Answered as of 1 Month Ago by tinstaafl and TnTinMN
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: