甜甜圈图表中的标签格式[实时图表]

时间:2018-12-18 12:08:26

标签: c# .net winforms

在Visual Studio for C#/ Winforms的LiveCharts Extension的甜甜圈图中,是否有任何形式的值/标签格式? 我有一个计时器,它用数据库sql的占用率更新图表。但是显示的值类似:53.3333335(精度太高)。我该如何调整?

    var request = new RestRequest("api/parks/" + parkId + "/occupancy");
    request.AddHeader("Accept", "application/json");
    // execute the request
    response = client.Execute(request);
    var content = response.Content;
    java = new JavaScriptSerializer();
    List<Object> occupancy = java.Deserialize<List<Object>>(content);
    string[] partsDate = occupancy[2].ToString().Split(new[] { 'T' }, 
    2);
    DateTime dateNew = DateTime.Parse(partsDate[0] + " " + 
        partsDate[1]);

    float result = float.Parse(occupancy[1].ToString());
    //float oldResult = result;
    result.ToString("0.00");
    pieChart1.Series = new SeriesCollection
        {
            new PieSeries
            {
                Title = "Occupancy",
                Values = new ChartValues<float> {result},
                PushOut = 15,
                DataLabels = true,
        },
    };

以下是预览:

Preview

2 个答案:

答案 0 :(得分:0)

替换

result.ToString("0.00");

string result = float.Parse(result.ToString("0.00"),CultureInfo.InvariantCulture);

答案 1 :(得分:0)

result.ToString("0.00"); 

应替换为

result = (float) Math.Round((double)result,2);

您想将浮点数舍入到2位小数。