图表图形上的点不适合 y 线

Points on chart graphic don't fit y-lines

我的第二张图表上的点不符合 y 轴,您可以在此处看到:

积分值正好是 50.0000、49.9999、49.9998 和 50.0001。但他们不在线。当我添加点并随之增加 y 轴上的值数量时,点将适合 y 轴,就像 picture.

这是我的代码(对塞尔维亚文本值感到抱歉)

TacnostVage tacnost = bazaPodataka.UcitajTacnostVage(Convert.ToString(dataGridView2.SelectedRows[0].Cells[2].Value), Convert.ToInt32(comboBox18.Text));
            List<TestTacnostVage> testoviTacnost = bazaPodataka.UcitajTestoveTacnostVage(Convert.ToString(dataGridView2.SelectedRows[0].Cells[2].Value), Convert.ToInt32(comboBox18.Text));

            chart2.ChartAreas.Clear();
            chart2.Series.Clear();
            prikažiToolStripMenuItem.DropDownItems.Clear();
            tabeluToolStripMenuItem.DropDownItems.Clear();

            string format = Convert.ToString(vaga.Podeljak);
            format = format.Remove(format.Length - 1, 1) + "0";

            if (testoviTacnost.Count != 0)
            {
                for (int i = 0; i < tacnost.NominalneMase.Count(); i++)
                {
                    ChartArea area = new ChartArea();
                    Series series = new Series();

                    area.AxisY.MajorGrid.LineColor = Color.LightGray;
                    area.AxisX.MajorGrid.LineColor = Color.LightGray;
                    area.AxisY.LabelStyle.Format = format;
                    area.BorderColor = Color.LightGray;
                    area.BorderDashStyle = ChartDashStyle.Solid;
                    area.AxisY.Interval = vaga.Podeljak;
                    area.Name = "ChartArea" + (i + 1);
                    series.ChartType = SeriesChartType.Point;
                    series.ChartArea = "ChartArea" + (i + 1);
                    series.Name = "Tačka" + (i + 1);

                    string text = "";
                    TegoviTacnostVaga tegoviTacnost = bazaPodataka.UcitajTegoveTacnostVage(Convert.ToString(dataGridView2.SelectedRows[0].Cells[2].Value), Convert.ToInt32(comboBox18.Text), i);
                    if (tegoviTacnost != null)
                    {
                        for (int j = 0; j < tegoviTacnost.Proizvodjac.Count(); j++)
                        {
                            text += tegoviTacnost.Proizvodjac[j] + " ";
                            text += tegoviTacnost.SerijskiBrojevi[j] + " ";
                            text += tegoviTacnost.NominalneMase[j] + "g";
                            text += (j == tegoviTacnost.Proizvodjac.Count() - 1 ? "" : "\n");
                        }
                    }

                    series.LegendText = (text == "" ? "Nema podataka" : text);

                    for (int j = 0; j < testoviTacnost.Count(); j++)
                        series.Points.AddXY(testoviTacnost[j].RedniBrojTesta, testoviTacnost[j].RezultatiMerenja[i]);

                    area.AxisY.StripLines.Add(new StripLine() { BorderColor = Color.Red, IntervalOffset = (tacnost.RezultatiMerenja[i].Average() + koeficijentTacnost * ponovljivost.ReferentnaVrednost), Text = "Gornja granica: " + Convert.ToDouble(tacnost.RezultatiMerenja[i].Average() + koeficijentTacnost * ponovljivost.ReferentnaVrednost).ToString(format) });
                    area.AxisY.StripLines.Add(new StripLine() { BorderColor = Color.Red, IntervalOffset = (tacnost.RezultatiMerenja[i].Average() - koeficijentTacnost * ponovljivost.ReferentnaVrednost), Text = "Donja granica: " + Convert.ToDouble(tacnost.RezultatiMerenja[i].Average() - koeficijentTacnost * ponovljivost.ReferentnaVrednost).ToString(format) });

                    area.AxisY.Maximum = area.AxisY.StripLines[0].IntervalOffset + area.AxisY.Interval;

                    if (series.Points.FindMaxByValue().YValues[0] >= area.AxisY.Maximum)
                        area.AxisY.Maximum = series.Points.FindMaxByValue().YValues[0] + area.AxisY.Interval;

                    area.AxisY.Minimum = area.AxisY.StripLines[1].IntervalOffset - area.AxisY.Interval;

                    if (series.Points.FindMinByValue().YValues[0] <= area.AxisY.Minimum)
                        area.AxisY.Minimum = series.Points.FindMinByValue().YValues[0] - area.AxisY.Interval;

                    chart2.ChartAreas.Add(area);
                    chart2.Series.Add(series);
                }
            }  

我找到了解决办法,但我不确定这个解释是否正确。问题是 Y 轴最大值。图表 Axis-Y 间隔为 0.0001(4 位小数),但在我的代码中,我将最大值设为 StripLines IntervalOffset(超过 4 位小数)加上图表间隔(结果超过 4 位小数)。因此,当您的 Chars Axis-Y 最大值和您的间隔(如果您设置间隔)具有不同的小数位数时,可能会发生这种情况。所以我只是简单地将带状线 InvervalOffset 舍入为 4 位小数(在这种情况下),并将 Axis-Y Maximum 设置为像 Interval 一样有 4 位小数。