找回密码
 立即注册

QQ登录

只需一步,快速开始

FF123

注册会员

8

主题

21

帖子

59

积分

注册会员

积分
59
FF123
注册会员   /  发表于:2021-7-2 11:21  /   查看:3739  /  回复:11
C1Chart如何设置X轴的数据类型为string类型?

本帖子中包含更多资源

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

x

11 个回复

倒序浏览
Richard.Ma讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2021-7-2 12:31:08
沙发
问题已收到,下午验证后给你回复
回复 使用道具 举报
FF123
注册会员   /  发表于:2021-7-2 17:38:51
板凳
请问,现在有结果了吗?
回复 使用道具 举报
Richard.Ma讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2021-7-2 18:35:55
地板
X轴的数据类型取决于你绑定的数据源,绑定数据源并将数据源的字符串类型的列设置为X轴即可
通过设计器只能设置基于Point的数据,X轴自然是数字

https://www.grapecity.com/compon ... gthechartdirec.html
回复 使用道具 举报
FF123
注册会员   /  发表于:2021-7-2 18:51:18
5#
那每个点提示x轴信息怎么显示string
数据呢?我现在x轴是可以显示string
类型数据,
回复 使用道具 举报
Richard.Ma讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2021-7-5 09:23:23
6#
你说的是tooltip吗,
回复 使用道具 举报
FF123
注册会员   /  发表于:2021-7-5 09:33:13
7#
是的,虽然x轴显示的是string类型,但是tooltip提示 的x轴信息不是string类型的
回复 使用道具 举报
Richard.Ma讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2021-7-5 12:31:01
8#
本帖最后由 Richard.Ma 于 2021-7-5 14:20 编辑

可以参考下面的代码,给MouseMove事件中加入下面的代码,通过获取X轴当前点对应的datatable 中的数据项。显示为tooltip

  1.         void c1Chart1_MouseMove(object sender, MouseEventArgs e)
  2.         {
  3.             Point mp = e.Location;
  4.             double x = 0, y = 0;
  5.             c1Chart1.ChartGroups[0].CoordToDataCoord(mp.X, mp.Y, ref x, ref y);
  6.             ChartDataSeries ds = c1Chart1.ChartGroups[0].ChartData.SeriesList[0];
  7.             int di = XValueToIndex(ds, x);
  8.             c1SuperTooltip1.Show("X轴坐标:"+dt.Rows[di].ItemArray[1].ToString(), c1Chart1, e.Location);
  9.         }
  10.         int XValueToIndex(ChartDataSeries ds, double xval)
  11.         {
  12.       
  13.             double[] dates = (double[])ds.X.CopyDataOut(typeof(double[]));
  14.             if (dates == null)
  15.                 return 0;
  16.             int len = dates.Length;
  17.             double x1 = dates[0];
  18.             double x2 = dates[len - 1];
  19.             double index = (len - 1) * (xval - x1) / (x2 - x1);
  20.             if (index < 0)                 index = 0;             else if (index > len - 1)  
  21.                 index = len - 1;
  22.             return (int)Math.Round(index);
  23.         }
复制代码




回复 使用道具 举报
FF123
注册会员   /  发表于:2021-7-5 14:59:41
9#
这个能在c1chart的toolTipText显示吗?上述提到的方法我试过了有点不太合适
,我想在鼠标移到点上的时候才显示
回复 使用道具 举报
Richard.Ma讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2021-7-5 15:39:38
10#
c1chart的toolTipText没有办法显示X对应的文本,

刚才的代码可以改成这样子,对折线图使用

  1.         void c1Chart1_MouseMove(object sender, MouseEventArgs e)
  2.         {
  3.             Point mp = e.Location;
  4.   
  5.             int s=0, p=0, d=0,x=0,y=0;
  6.            
  7.             c1Chart1.ChartGroups[0].CoordToDataIndex(mp.X, mp.Y, CoordinateFocusEnum.XandYCoord, ref s, ref p, ref d);
  8.             c1Chart1.ChartGroups[0].DataIndexToCoord(s, p,ref x,ref y);
  9.             if (d < 20&& p >= 0)
  10.             {

  11.                     c1SuperTooltip1.Show("X轴坐标:" + dt.Rows[p].ItemArray[1].ToString(), c1Chart1, new Point(x,y));
  12.             }
  13.             else
  14.             {
  15.                 c1SuperTooltip1.Hide();
  16.             }

  17.         }
复制代码
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部