我有这个 ZedGraph 控制代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZedGraph;
using Extracting_Frames;
namespace Lightnings_Extractor
{
public partial class Histogram_Graphs : Form
{
public long[] histogram;
public Histogram_Graphs()
{
InitializeComponent();
histogram = Form1.GetHistogramValue;
this.DoubleBuffered = true;
CreateGraph_GradientByZBars(zedGraphControl1);
}
private void Histogram_Graphs_Load(object sender, EventArgs e)
{
}
private void CreateGraph_GradientByZBars(ZedGraphControl z1)
{
GraphPane myPane = z1.GraphPane;
myPane.Title.Text = "Demonstration of Multi-Colored Bars with a Single BarItem";
myPane.XAxis.Title.Text = "Bar Number";
myPane.YAxis.Title.Text = "Value";
PointPairList list = new PointPairList();
Random rand = new Random();
for (int i = 0; i < histogram.Length; i++)
{
double x = (double)i + 1;
//double y = (double)i + 1;//rand.NextDouble() * 1000;
double z = i / 4.0;
list.Add(x, histogram[i], z);
}
BarItem myCurve = myPane.AddBar("Multi-Colored Bars", list, Color.Blue);
Color[] colors = { Color.Red, Color.Yellow, Color.Green, Color.Blue, Color.Purple };
myCurve.Bar.Fill = new Fill(colors);
myCurve.Bar.Fill.Type = FillType.GradientByZ;
myCurve.Bar.Fill.RangeMin = 0;
myCurve.Bar.Fill.RangeMax = 4;
myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(220, 220, 255), 45);
myPane.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 225), 45);
// Tell ZedGraph to calculate the axis ranges
z1.AxisChange();
}
}
}
问题出在循环中:
for (int i = 0; i < histogram.Length; i++)
{
double x = (double)i + 1;
//double y = (double)i + 1;//rand.NextDouble() * 1000;
double z = i / 4.0;
list.Add(x, histogram[i], z);
}
Y 之前是随机的。现在我想使用直方图列表中的值。 因此,例如在索引 [0] 中有一个数字:34118 然后在索引 1 中1521索引[2] 522 列表中有256个索引。
当我看到图表时,看到吟游诗人的高度非常非常矮。
在图表的开头,我看到一条线非常高,但接下来的所有线都非常短。 在 Y 轴上,我看到边上的数字从 0 到 40,在 x 轴上,我看到数字从 0 到 300。
在 Y 轴上,我应该看到从 0 到直方图中最高值的数字,我猜在 X 轴上,我应该看到从 0 到 256 的数字。
这里乱七八糟。
我该如何解决?
谢谢。
最佳答案
您的代码中没有错误。您的图表准确绘制了 histogram[]
数组中的值。
您提到您的数组包含以下值:
histogram[0] = 34118
histogram[1] = 1521
histogram[2] = 522
...
如果您检查您的屏幕截图,这些图是正确的。绘制的第一个条形非常高,其他剩余值(符合您的预期)接近 1x10^3 strip 。您的 histogram[]
数组可能正在使用错误的数据或索引 [0]
处的错误数据进行初始化。
我只能从您的代码和数据的这边推测 histogram[0]
中的值的重要性,但也许您收到的数组包含所有索引 [0]
中的剩余数据。
作为预期的快速检查,如果您将循环更改为从索引 [1]
而不是 [0]
开始,您将看到情节控制您正在使用的将对预期接近 1x10^3 波段的所有其他值正确执行,并且您应该检查填充 histogram
数组的数据源以查看第一个数据点是否相关或已设置为错误值。
for (int i = 1; i < histogram.Length; i++)
{
double x = (double)i + 1;
//double y = (double)i + 1;//rand.NextDouble() * 1000;
double z = i / 4.0;
list.Add(x, histogram[i], z);
}
关于c# - 为什么在 ZedGraph 中 Y 轴很小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13111010/