找回密码
 立即注册

QQ登录

只需一步,快速开始

lvGrap

初级会员

3

主题

11

帖子

350

积分

初级会员

积分
350

活字格认证

lvGrap
初级会员   /  发表于:2014-8-12 10:30  /   查看:4991  /  回复:4

时间类型的Axis,AutoMajor = false,在设置UnitMajor时总会将整刻度自动加入,如何解决?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

4 个回复

倒序浏览
lvGrap
初级会员   /  发表于:2014-8-12 10:56:00
沙发
示例代码
this.c1Chart1.ChartArea.AxisX.AutoMax = false;
            this.c1Chart1.ChartArea.AxisX.AutoMin = false;
            this.c1Chart1.ChartArea.AxisX.Min = DateTime.Now.ToOADate();
            this.c1Chart1.ChartArea.AxisX.Max = DateTime.Now.AddHours(2.5).ToOADate();
            this.c1Chart1.ChartArea.AxisX.AnnoFormat = C1.Win.C1Chart.FormatEnum.DateShortTime;

            DateTime nowDateTime = DateTime.Now;
            double oneMinute = nowDateTime.AddMinutes(1).ToOADate() - nowDateTime.ToOADate();
            this.c1Chart1.ChartArea.AxisX.UnitMajor = 14.0 * oneMinute;
            this.c1Chart1.ChartArea.AxisX.AutoMajor = false;
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2014-8-12 12:19:00
板凳
回复 2楼lvGrap的帖子

你可以使用ValueLabel,让刻度显示标签,给每个刻度一个日期的标签。代码如下:
  1.             DateTime nowDateTime = DateTime.Now;
  2.             Axis ax = c1Chart1.ChartArea.AxisX;
  3.             ax.AnnoMethod = AnnotationMethodEnum.ValueLabels;
  4.             ax.Max = 9;
  5.             ax.Min = 0;
  6.             string label = "";
  7.             for (int i = 0; i < 10; i++)
  8.             {
  9.                 label = nowDateTime.ToString("hh:mm");
  10.                 ax.ValueLabels.Add(i, label);
  11.                 nowDateTime = nowDateTime.AddMinutes(14);
  12.             }
复制代码
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
lvGrap
初级会员   /  发表于:2014-8-12 14:46:00
地板
回复 3楼Alice的帖子

可以实现。但是最好ax.max和ax.min仍然用时间,然后修改下面的语句。否则输入时间数据会有问题。
ax.ValueLabels.Add(i, label);
---->
ax.ValueLabels.Add(nowDateTime.ToOADate(), label);
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2014-8-12 18:05:00
5#
回复 4楼lvGrap的帖子

思路和我之前说的相似,用ValueLabel来展示时间,然后将Max/Min值设置为nowDateTime.ToOADate。建立ValueLabel和Value的对应关系。最后将AxisX.TickMinor设置为TickMarkersEnum.None.代码参考:
  1.             DateTime nowDateTime = DateTime.Now;
  2.             Axis ax = c1Chart1.ChartArea.AxisX;
  3.             ax.AnnoMethod = AnnotationMethodEnum.ValueLabels;
  4.             ax.Min = nowDateTime.ToOADate();
  5.             ax.Max = nowDateTime.AddHours(2.5).ToOADate();

  6.             string label = nowDateTime.ToString("hh:mm");
  7.             double value = ax.Min;
  8.             do
  9.             {
  10.                 ax.ValueLabels.Add(value, label);
  11.                 nowDateTime = nowDateTime.AddMinutes(14);
  12.                 value = nowDateTime.ToOADate();
  13.                 label = nowDateTime.ToString("hh:mm");
  14.             } while (value <= ax.Max);
  15.             ax.TickMinor = TickMarksEnum.None;
复制代码
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部