3

Let's suppose I have a Winforms app with a Dictionary that looks like this:

private Dictionary<string, double> ChartCollection = new Dictionary<string, double>();

And let's suppose that I populate this dictionary with the number of each type of various foe which I've recently slain:

Ninja, 7
Pirate, 10
Space Cowboy, 4
Zombie, 8
Vampire, 7

Finally, let's suppose I bind a chart to this data like so:

chtAgentVersions.Series[0].Points.DataBindXY(ChartCollection.Keys, ChartCollection.Values);

This works flawlessly. I get my graph and a legend made up of my foe names and everything just fine. But when I try to apply this code:

chtAgentVersions.Series[0].Label = "#VALX (#PERCENT)";

...the labels on my legend change from their appropriate foe names to zeroes. Upon inspection of the Series after the databinding, I find that the names of my foes are actually not getting written to the XValues. I even tried this:

chtAgentVersions.Series[0].XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.String;

But, to no avail. Why are they all zeroes?

Chris Zeh
  • 924
  • 8
  • 23
Chris Barlow
  • 3,274
  • 4
  • 31
  • 52

1 Answers1

2

If you're using strings as your XValue, use #AXISLABEL instead of #VALX since the XValue is always zero when used with strings.

Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
  • Bah-zing, you got it. I'll mark you as the answer in 9 minutes. =) – Chris Barlow Jan 23 '12 at 20:25
  • Hey - i don't mean to bug you, but you don't have a good resource for the free-text dictionary associated with the Series object do you? I can't find anything googling, and the key-value pairs are so esoteric I don't know where to begin... This is what I'm talking about: chtAgentVersions.Series[0]["PieLabelStyle"] = "Disabled"; – Chris Barlow Jan 23 '12 at 20:33
  • There's a sample project with lots of samples regarding Charting controls. Here's the link: http://archive.msdn.microsoft.com/mschart You can download and run the project to play with the rich set of properties.... – Leniel Maccaferri Jan 23 '12 at 20:38
  • 1
    Oh... I found the list with esoteric names hehehe =) http://msdn.microsoft.com/en-us/library/dd456764.aspx – Leniel Maccaferri Jan 23 '12 at 20:49
  • 1
    You're the friggn' Sherlock Holmes of Microsoft Charts. Thank you, sir. =) – Chris Barlow Jan 23 '12 at 21:15