Zedgraph:带日期轴的水平条形堆栈

时间:2012-10-22 15:47:00

标签: c# zedgraph

我尝试用C#中的ZedGraph创建一个水平条形堆栈。 我已经实现了this。 这张图片应该是一种日历,一个酒吧大小30分钟,红色条表示忙,绿色表示空闲时间。

但是,正如您所看到的,X值(时间)并不好。该图片仅代表一天(我的XDate()数据从20/12/2011 0h0m0s到21/12/2011 0h0m0s)但如果我缩放我有9999年年份..

这是我的代码。我无法找到我的错误。

谢谢你的帮助。

gPane.BarSettings.Type = BarType.Stack;
gPane.BarSettings.Base = BarBase.Y;
gPane.BarSettings.ClusterScaleWidth = 1; // Widen bars

gPane.XAxis.Title.Text = "Time (sec)";
gPane.XAxis.Scale.FontSpec.Angle = 65f;
gPane.XAxis.Type = AxisType.Date;
gPane.XAxis.Scale.Format = "dd-MMM-yy hh:mm";
gPane.XAxis.Scale.BaseTic = dataBar[0].X;
gPane.XAxis.Scale.Min = dataBar[0].X;
gPane.XAxis.Scale.Max = dataBar[dataBar.Count - 1].X;
gPane.XAxis.Scale.MajorUnit = DateUnit.Day;
gPane.XAxis.Scale.MinorUnit = DateUnit.Day;
gPane.XAxis.Scale.MinorStep = 1;
gPane.XAxis.Scale.MajorStep = 2;

foreach (PointPair pp in dataBar)
{
    //pp.X = XDate date (double)
    //pp.Y = 0 (free) ou 1 (busy)

    Color col = Color.Green;
    if (pp.Y == 1)
        col = Color.Red;

    gPane.AddBar("", /* I don't need it */
                new double[] { pp.X }, /* the current XDate date*/
                new double[] { 30 /* width of bar */ },
                col);
}

gPane.AxisChange();

1 个答案:

答案 0 :(得分:0)

你是否尝试在添加条形图时控制你的XDate obj? 尝试xDate.AddDays(1)来控制你的xAxis值。