Winform中的图表显示错误的点 [英] Chart in winform displaying wrong Point

查看:101
本文介绍了Winform中的图表显示错误的点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码. 我已经对x和y值进行了硬编码以进行测试. 并出于某种原因绘制了点(0,-0.5)(1,-0.5) 对于我一生,我不知道发生了什么,因为如果尝试其他值,则图形将正确显示.

I have the following code. I have hardcoded the x and y values to test. And for some reason for the point (0,-0.5) it plots (1,-0.5) For the life of me I do not know what is going on, because if you try other values then the graph displays correctly.

foreach (var grp in q)
            {
                point = new DataPoint();
                 Sum1 = grp.Sum1 > 2 ? 2 : grp.Sum1;
                Sum1 = Sum1 < -2 ? -2 : Sum1;

                Sum2 = grp.Sum2 > 2 ? 2 : grp.Sum2;
                Sum2 = Sum2 < -2 ? -2 : Sum2;

                point.XValue = 0;
                point.YValues = new double[] { -0.5 };

                chart1.Series.Add(grp.Id.ToString());
                chart1.Series[grp.Id.ToString()].ChartType = SeriesChartType.Point;
                chart1.Series[grp.Id.ToString()].Label = grp.Id.ToString();
                chart1.Series[grp.Id.ToString()].Points.Add(point);
                chart1.Series[grp.Id.ToString()].ToolTip = "THEMES = " + Sum1 + "\n PRICES = " + Sum2;
                chart1.Series[grp.Id.ToString()].LabelToolTip = "THEMES = " + Sum1 + "\n PRICES = " + Sum2;
                chart1.Series[grp.Id.ToString()].MarkerSize = 11;

                chart1.Update();

                if (grp.Id.ToString() == "WW" || grp.Id.ToString() == "PB"
                    || grp.Id.ToString() == "AJ" || grp.Id.ToString() == "AK")
                {
                    avgTheme += (float)Sum1;
                    avgPrice += (float)Sum2;
                    count++;
                }
            }

更新:

此行需要添加,仅适用于.NET 4.5

this line needed to be added, works only with .NET 4.5

          chart1.Series["ABC"].CustomProperties = "IsXAxisQuantitative=True";

推荐答案

这真的很奇怪!看起来像一个很难相信的错误.我玩了一下,但只能确认似乎没有办法将单个Point设置为Series中的位置0.

This is really weird! Looks like a very hard to believe bug. I played around but can only confirm that there seems to be no way to set a single Point to position 0 in a Series.

这是一个愚蠢的解决方法:

S1.ChartType = SeriesChartType.Point;

for (int i=0; i < 2; i++)
{
    DataPoint point = new DataPoint();
    point.SetValueXY(i, -0.5);
    if (i > 0) point.Color = Color.Transparent;
    S1.Points.Add(point);
}

我希望我知道这是怎么回事-Chart文献记载如此欠缺,仍然可能有些疯狂的系统.

I wish I knew what this is about - Chart is so ill-documented there might still be some system to the madness..

更新:添加Timer并让其Tick删除透明的第二个Point时,您可以看到第一个Point如何从0跳到1.太奇怪了.

Update: When you add a Timer and let its Tick remove the transparent 2nd Point, you can see how the 1st Point jumps from 0 to 1. So weird..

这篇关于Winform中的图表显示错误的点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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