gpt4 book ai didi

c# - 在 Windows 窗体应用程序折线图中输入过高的数字时的视觉错误

转载 作者:行者123 更新时间:2023-12-04 09:15:15 25 4
gpt4 key购买 nike

我正在使用 C# 尝试将数字从文本文件输入到折线图中。文本文件中的数字很大,如 -30000。每次我在图表中输入大量数字时,都会出现视觉故障,使图表变黑。我做错了什么还是一个错误?
Picture of graph when inputting large numbers

void ChartLoad()
{
var chart = LineGraph.ChartAreas[0];

chart.AxisX.IntervalType =
System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;

chart.AxisX.LabelStyle.Format = "";
chart.AxisY.LabelStyle.Format = "";
chart.AxisX.LabelStyle.IsEndLabelVisible = true;

chart.AxisX.Interval = 0.5;
chart.AxisY.Interval = 10;

LineGraph.Series[0].IsVisibleInLegend = false;

LineGraph.Series.Add("Line1");
LineGraph.Series["Line1"].ChartType =
System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
LineGraph.Series["Line1"].Color = Color.Green;

LineGraph.Series.Add("Line2");
LineGraph.Series["Line2"].ChartType =
System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
LineGraph.Series["Line2"].Color = Color.Blue;

LineGraph.Series["Line1"].Points.AddXY(30000, 30000);
LineGraph.Series["Line1"].Points.AddXY(-30000, -30000);
}

最佳答案

问题是网格。与您的值范围相比,您的区间非常小。网格非常紧密,以至于它在您的图表上缠上了一层狭窄的网格线。
你可以解决它

  • 电网切换:
     chart.AxisX.MinorGrid.Enabled = false;
    chart.AxisX.MajorGrid.Enabled = false;
    chart.AxisY.MajorGrid.Enabled = false;
    chart.AxisY.MinorGrid.Enabled = false;
  • 或者根据您的值的范围将轴间隔调整为合理的数字。当您将间隔设置为:
     chart.AxisX.Interval = 10000;
    chart.AxisY.Interval = 10000;

  • 这是一种可以为您执行此操作的方法:
    private void AddValuesAndAdjustInterval(string series, double xValue, double yValue)
    {
    LineGraph.Series[series].Points.AddXY(xValue, yValue);

    var chart = LineGraph.ChartAreas[0];

    double maxValueX = LineGraph.Series[series].Points.Select(x=> x.XValue).Max();
    double minValueX = LineGraph.Series[series].Points.Select(x=> x.XValue).Min();
    double maxValueY = LineGraph.Series[series].Points.SelectMany(x=> x.YValues).Max();
    double minValueY = LineGraph.Series[series].Points.SelectMany(x => x.YValues).Min();

    int stepSize = 20; // the smaller this value the larger the grid separation

    chart.AxisX.Interval = (maxValueX - minValueX) / stepSize;
    chart.AxisY.Interval = (maxValueY - minValueY) / stepSize;
    }
    现在您可以使用它来添加值:
    AddValuesAndAdjustInterval("Line1", 30000, 30000);
    AddValuesAndAdjustInterval("Line1", -30000, -30000);

    关于c# - 在 Windows 窗体应用程序折线图中输入过高的数字时的视觉错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63253978/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com