Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在ms图表控件中格式化轴_C#_Format_Axis_Mschart_Invariantculture - Fatal编程技术网

C# 如何在ms图表控件中格式化轴

C# 如何在ms图表控件中格式化轴,c#,format,axis,mschart,invariantculture,C#,Format,Axis,Mschart,Invariantculture,我正在使用ms图表控件,并希望执行以下操作: 将图表区域[0]的Y轴格式化为特定格式。在这种情况下,它应该是一个不带小数的数字,并用一个点分组(每千个) 试过了: chart1.ChartAreas[0].AxisY.LabelStyle.Format=“{#.####}” 但这并没有给我正确的结果。 因此,我尝试获取FormNumber事件并使用以下内容进行测试: if(e.ElementType == System.Windows.Forms.DataVisualization.Charti

我正在使用ms图表控件,并希望执行以下操作: 将图表区域[0]的Y轴格式化为特定格式。在这种情况下,它应该是一个不带小数的数字,并用一个点分组(每千个)

试过了: chart1.ChartAreas[0].AxisY.LabelStyle.Format=“{#.####}”

但这并没有给我正确的结果。 因此,我尝试获取FormNumber事件并使用以下内容进行测试:

if(e.ElementType == System.Windows.Forms.DataVisualization.Charting.ChartElementType.AxisLabels)// && e.SenderTag!=null)
{
    e.LocalizedValue = e.Value.ToString("#.###", _numberFormatInfo);
}
使用:

NumberFormatInfo _numberFormatInfo;
_numberFormatInfo = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone();
_numberFormatInfo.NumberGroupSeparator = ".";
_numberFormatInfo.NumberDecimalSeparator = ",";

.ToString("#,0.00", _numberFormatInfo));
不起作用,但通常情况下,如果您有以下情况:

decimal myDec = 123456.789;
string test = myDec.ToString("#,0.00", _numberFormatInfo));
chart1.ChartAreas[0].AxisY.LabelStyle.Format = "MyAxisYCustomFormat";
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "MyAxisXCustomFormat";
测试将返回123.456789(与用户计算机上的区域性设置无关)

但这似乎对ms图表控件不起作用

有人能告诉我如何做到以下几点吗:

在chartArea[0]中设置Y值的格式,不带小数,并使用一个点作为组分隔符。同时,将x值设置为dd MM格式(如10月16日至10日=>16日),而该值实际上是Uint 20131016。 格式必须独立于区域性设置。 希望有人能帮我。 亲切问候,


Matthijs

我让它像这样工作:

decimal myDec = 123456.789;
string test = myDec.ToString("#,0.00", _numberFormatInfo));
chart1.ChartAreas[0].AxisY.LabelStyle.Format = "MyAxisYCustomFormat";
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "MyAxisXCustomFormat";
使用图表控件的NumberFormat事件:

private void chart1_FormatNumber(object sender, System.Windows.Forms.DataVisualization.Charting.FormatNumberEventArgs e)
{
    if(e.ElementType == System.Windows.Forms.DataVisualization.Charting.ChartElementType.AxisLabels)
    {
        switch(e.Format)
        {
            case "MyAxisXCustomFormat":
                e.LocalizedValue = DateTime.ParseExact(e.Value.ToString(), "yyyyMMdd", null).ToString("dd-MM");
                break;
            case "MyAxisYCustomFormat":
                e.LocalizedValue = e.Value.ToString("#,###", _numberFormatInfoNLV);
                break;
            default:
                break;
        }
    }
}

所有的工作都像我想要的;-)

做一些可能有用的事情。如果有。我将添加代码您是否尝试将格式设置为
,####0.###
,在这种情况下,它确实有效,但我的客户希望获得千人分组的分数。