Zedgraph - 如何自定义基于X轴的tics [英] Zedgraph - how to customize date based X-Axis tics

查看:406
本文介绍了Zedgraph - 如何自定义基于X轴的tics的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现状

我使用ZedGraph构建一个价格(Y轴)对时间(X轴)的图表。

I am building a chart using ZedGraph of price (Y axis) against time (X axis). The duration of time is three years.

现在我得到X轴标签:Jan 11; Jan 12; 1月13日的一组数据,从2010年3月3日到2013年3月2日。

At the moment I'm getting X axis labels of : Jan 11; Jan 12; Jan 13 for a set of data that runs from 3-Mar-2010 to 2-Mar-2013.

据我所见,这是默认行为,如果轴是DateTime类型。

As far as I can see this is default behaviour if the axis is of type DateTime.

QUESTION

如何更改X轴标签,使我得到:3月11日; 3月12日; 3月13日?

How do I change the X axis labelling so that I get: Mar 11; Mar 12; Mar 13 ? And more generally so that I can change the labels used to coincide with the start/end month of the data.

我对这个问题的初步尝试有点含糊,所以我只是想澄清一下。

My initial attempt at this question was a little ambiguous so I'm just going to try to clarify.

这不是我想要的标签是dd-MMM-yy - 我想要的是能够控制在X轴的位置标签/ tics出现。

It's not that I want the labels to be dd-MMM-yy - what I want is to able to control the locations on the X axis where the labels/tics appear.

因此,对于横跨2010年3月3日至2013年3月2日的X轴,而不是始终出现在1月的标签

So that, for an X-axis that spanned 3-Mar-2010 to 2-Mar-2013, instead of the labels always appearing in January


  • Jan 11 [2011年1月];

  • Jan 12 [2012年1月];

  • 1月13日(即2013年1月)

选择标签/ tic出现在哪个月份。因此,对于该数据集,我想在以下位置添加标签:

as shown in my screen dump I can choose which month the label/tic appears in . So for that data set I would like to have labels at :


  • 2010年3月(显示为Mar10)

  • 2011年3月(显示为Mar11)

  • 2012年3月(显示为Mar12)


  • March 2010 (appearing as Mar10)
  • March 2011 (appearing as Mar11)
  • March 2012 (appearing as Mar12)
  • March 2013 (appearing as Mar13)

我希望更清楚。

推荐答案

需要将x轴属性设置为

myPane.XAxis.Title.Text = "Date";
myPane.XAxis.Type = AxisType.Date;
myPane.XAxis.Scale.Format = "dd-MMM-yy";
myPane.XAxis.Scale.MajorUnit = DateUnit.Day;
myPane.XAxis.Scale.MajorStep = 1;
myPane.XAxis.Scale.Min = new XDate(DateTime.Now.AddDays(8));
myPane.XAxis.Scale.Max = new XDate(DateTime.Now.AddDays(11));

这会给你你要求的日期;我知道你可以在 AddDays 方法中放一个减号,如果你想从今天开始倒计时,你也可以特别设置日期(只看看自动完成当你开始键入)。

That would give you the dates you requested; I know you can put a minus sign in the AddDays method if you want to count down from today instead, and you can set dates specifically too (just look at the autocomplete when you start typing it).

希望这有助于!好运!

EDIT

以获取这些自定义标记:
您必须使用 TextObj 标签。您还必须删除原始的蜱:

So here is what I could figure out to get those custom ticks: You have to use TextObj labels. You'll also have to get rid of the original ticks:

pane1.MasterPane[0].XAxis.Scale.IsVisible = false;
pane1.MasterPane[0].XAxis.MajorTic.IsAllTics = false;

foreach (double val in x_values)
{
    TextObj text = new TextObj(val.ToString(), pane1.MasterPane[0].YAxis.Scale.Min, val);
    text.Location.AlignH = AlignH.Right;
    text.FontSpec.Border.IsVisible = false;
    text.FontSpec.Fill.IsVisible = false;
    pane1.MasterPane[0].GraphObjList.Add("Mar10"); 

    LineObj line = new LineObj(pane1.MasterPane[0].YAxis.Scale.Min, val, pane1.MasterPane[0].YAxis.Scale.Max, val);
    line.Line.Style = System.Drawing.Drawing2D.DashStyle.Dash;
    line.Line.Width = 1f;
    pane1.MasterPane[0].GraphObjList.Add(line);
}

我从这个线程,我认为是类似于你的,除了它是 Y -axis 。这是一个黑客,你必须手动添加每一个。你真的不需要在一个 foreach 循环中,我把它放在一个,因为这是我从另一个帖子复制代码。我希望它工作!

I modified this from this thread which I think is similar to yours, except it is for the Y-axis. It is a bit of a hack and you'll have to add each one manually. You don't really have to do it in a foreach loop, I just put it in one because that is how I copied the code from the other post. I hope it works!

这篇关于Zedgraph - 如何自定义基于X轴的tics的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆