Search code examples
c#winformschartsmschart

Chart X Axis wrong labels


I have a chart and a datagridview, both of them are databound to a dictionary, for example:

freqChart.Series[0].Points.DataBindXY(symCount.Keys, symCount.Values);

And on the screenshot below you can see the difference in X-Axis label/key names. Datagridview shows it correctly, while chart flips char if it's punctuation char. What's the problem? How do I fix it?

Screenshot (Chart and DataGridView):

enter image description here


Solution

  • My comment was wrong; in fact this is a funny effect you get when you have a RightToLeft turned on.

    There are several values but this one is enough to reproduce:

    freqChart.RightToLeft = RightToLeft.Yes
    

    Either this is what you want, then you can turn it on for the DGV as well; or it isn't then simply turn it off..

    freqChart.RightToLeft = RightToLeft.No
    

    As you can see it is a Control.Property so it will work on all controls. Also to be noted: The RightToLeft property is an ambient property, so it propagates to child controls.

    Why it acts so strangly I can't say, though. The docs basically talk about alignment, not punctuation. If you are interested you may want to read up on it in wikipedia