gpt4 book ai didi

c# - 尝试使用 ZedGraph 创建直方图

转载 作者:行者123 更新时间:2023-11-30 16:32:37 24 4
gpt4 key购买 nike

我正在尝试使用 ZedGraph 创建直方图。

条形图和数据都很好,唯一需要的是我的条形图位于抽动点之间,而不是直接在抽动点上。

示例数据:

1, 4
2, 8
3, 1

意味着我有:

4 items that are >= 0 and < 1
8 items that are >= 1 and < 2
1 item that is >= 2 and < 3

所以目前我的条形图当然直接出现在控制点(x 值)1、2 和 3 上。

但我想看看:

  • 控制点 0 和 1 之间的第一个小节,
  • 控制点 1 和控制点 2 之间的第二个小节
  • 第 2 节和第 3 节之间的第三个小节

为了实现这一目标,需要调整什么属性?我目前正在查看 XAxisXAxis.Scale,但我还没有找到任何东西......

最佳答案

您可能无法使用普通的 BarItem 来做到这一点。我使用 BoxObj 对象来创建直方图。

如果 histList 是包含您的直方图值对(断点和值)的 PointPairList,您可以使用:

for (int i = 0; i < histList.Count - 1; i++)
{
BoxObj box = new BoxObj(histList[i].X, histList[i].Y, histList[i + 1].X - histList[i].X, histList[i].Y);
box.IsClippedToChartRect = true;
box.Fill.Color = myColor;
pane.GraphObjList.Add(box);
}

使用BoxObj,您可以完全控制栏的位置等。更多信息请参见documentation

编辑
请记住,在使用 BoxObj(或一般的任何 GraphObj)时,不会自动设置 X 和 Y 比例。您需要手动设置比例范围:

pane.XAxis.Scale.Min = ...
pane.XAxis.Scale.Max = ...
pane.YAxis.Scale.Min = ...
pane.YAxis.Scale.Max = ...

关于c# - 尝试使用 ZedGraph 创建直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3901564/

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