在Y轴上显示Y值而不舍入 [英] Display Y-Values on Y-Axis without rounding

查看:189
本文介绍了在Y轴上显示Y值而不舍入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何清除图表中的圆角OY?



我传送格式为1,3546的值,图表显示为1,35。

解决方案

对于给定的 Axis ,您可以设置 LabelStyle.Format



例如,您可以使用:

 <$> c $ c> chart1.ChartAreas [area1]。AxisX.LabelStyle.Format =000.000\\%; 

或:

  chart1.ChartAreas [0] .AxisY.LabelStyle.Format =###,## 0.00000; 

注意:格式化 code>轴网格,因此您认为是舍入。实际上它是 GridLines 的值 DataPoints



要显示 DataPoints 的Y值,您有三个选项,我知道,


li>

当鼠标在点上时,您可以将它们显示为工具提示


  • ,或者您可以在 CustomLabels 沿Y轴,这可能是你想要的。请注意,如果




    • 只有非常有限的数据点数,则这将是一个有用的选项

    • 这些点的距离相当远。


  • CustomLabels 将重叠。



    设置 CustomLabels 有点棘手。这里是一段代码,每个数据点设置一个。如上所述,您可能需要插入支票以防止重叠。

      //支持几个简短名称
    ChartArea CA = chart1.ChartAreas [0];
    系列S1 = chart1.Series [0];

    //这将是选项一:
    S1.IsValueShownAsLabel = true;

    //清除任何先前的CustomLabels
    CA.AxisY.CustomLabels.Clear();
    //我们创建一个版本的点集合,按Y值排序:
    List< DataPoint> ptS = S1.Points.OrderBy(x => x.YValues [0])。ToList();

    //现在,对于选项三,我们添加自定义标签:
    for(int p = 0; p< ptS.Count; p ++)
    {
    CustomLabel L = new CustomLabel(ptS [p] .YValues [0] - 0.5,
    ptS [p] .YValues [0] + 0.5,
    ptS [p] .YValues [0] .ToString ## 0.0000),
    0,LabelMarkStyle.None);
    CA.AxisY.CustomLabels.Add(L);

    //这是选项二:每个点的工具提示
    ptS [p] .ToolTip = ptS [p] .YValues [0] .ToString(## 0.0000);
    }

    CustomLabel 是关于Y位置或实际上它们应该标记的Y值范围。接下来的值,格式化为显示您想要的小数位数。



    这是一个显示所有三个选项在工作的屏幕截图:




    How to remove rounding axis OY in Chart ?

    I pass a value in the format 1,3546 and the graph shows 1,35.

    解决方案

    For a given Axis you can set the LabelStyle.Format.

    For example you can use this :

      chart1.ChartAreas["area1"].AxisX.LabelStyle.Format = "000.000\\%";     
    

    or this:

      chart1.ChartAreas[0].AxisY.LabelStyle.Format = "###,##0.00000";
    

    Note: This formats the Label of the Axis Grid, hence what you perceive as rounding. In fact it is the value for the GridLines not the Values of the DataPoints!

    To display the Y-Values of the DataPoints you have three options I know of and I'll show you each:

    1. You can display them inside the graph with each point

    2. You can display them as tooltips when the mouse is over a point

    3. or you can display them in CustomLabels along the Y-Axis, which may be what you want. Please note that this will only be a useful option if

      • There is a very limited number of data points
      • Those points are sped reasonably far apart

    If one or both conditions are not met, the CustomLabels will overlap.

    Setting CustomLabels is somewhat tricky. Here is a piece of code that sets one per each data point. As noted you may need to insert checks to prevent the overlapping..

    // propare a few short names
    ChartArea CA = chart1.ChartAreas[0];
    Series S1 = chart1.Series[0];
    
    // this would be option one:
    S1.IsValueShownAsLabel = true;
    
    // we clear any previous CustomLabels
    CA.AxisY.CustomLabels.Clear();
    // we create a version of our points collection which sorted  by Y-Values:
    List<DataPoint> ptS = S1.Points.OrderBy(x => x.YValues[0]).ToList();
    
    // now, for option three we add the custom labels:
    for (int p = 0; p < ptS.Count; p++)
    {
        CustomLabel L = new CustomLabel(ptS[p].YValues[0] - 0.5, 
                                        ptS[p].YValues[0] + 0.5,  
                                        ptS[p].YValues[0].ToString("##0.0000"), 
                                        0, LabelMarkStyle.None);
        CA.AxisY.CustomLabels.Add(L);
    
        // this is option two: tooltips for each point
        ptS[p].ToolTip = ptS[p].YValues[0].ToString("##0.0000");
    }
    

    The first two parameters of a CustomLabel are about the Y-position or actually the Y-Value range they are supposed to label. Next the value, formatted to show the decimal digits you wanted. Finally first row of labels and no tickmarks.

    Here is a screenshot that shows all three options at work:

    这篇关于在Y轴上显示Y值而不舍入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆