Search code examples
c#formattingteechart

Labels ValueFormat is ignored


How can I change the decimal separator for a Steema TeeChart Axis Label to be . instead of a ,?

I checked the tutorial which stated that:

Label formats You may apply all standard number and date formats to Axis labels. The Axis page, Labels section contains the field "Values format". If your data is datetime the field name changes to "Date time format". At runtime use:

[C#.Net] tChart1.Axes.Bottom.Labels.ValueFormat = "#,##0.00;(#,##0.00)";

I tried this but it seems to be ignored when I use custom ValueFormats. If I use C for instance a currency is attached, and if I use 0.# I get one decimal, but the separator is still a ,.

I can listen to the m_Chart.GetAxisLabel and I see that the ValueFormat is the same as the one I entered, and the e.LabelText is 0,00. I can then modify the e.LabelText to be "0.00" instead. However, I would much rather use a Format specifier for this.

Is it possible to change a format specifier for a chart to use . instead of , when displaying numbers?

A short example of what I am doing:

public MainWindow()
{
    InitializeComponent();
    Line line = new Line();
    Random random = new Random();

    //line.Add(101, 1000);
    for (int i = 0; i < 100; i++)
    {
        line.Add(i, random.Next(100)/100.0f);
    }

    line.XValues.DateTime = false;
    m_Chart.Series.Add(line);

    m_Chart.Legend.Visible = false;
    m_Chart.Aspect.View3D = false;
    m_Chart.Axes.Left.Labels.ValueFormat = "# ##0.00";

    // I _can_ use this, but rather not.
    //m_Chart.GetAxisLabel += OnGetAxisLabel;
}

Solution

  • This looks like a .NET Framework issue to me. You could try setting the NumberFormatInfo.NumberDecimalSeparator Property. For example, code below does it for me.

      System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(System.Globalization.CultureInfo.InvariantCulture.Name, true);
      ci.NumberFormat.NumberDecimalSeparator = ".";
      System.Threading.Thread.CurrentThread.CurrentCulture = ci;