找回密码
 立即注册

QQ登录

只需一步,快速开始

安心海叶

中级会员

66

主题

255

帖子

717

积分

中级会员

积分
717

活字格认证微信认证勋章

安心海叶
中级会员   /  发表于:2018-10-18 09:26  /   查看:3308  /  回复:5
你好!

      想问一下,在WPF平台下,使用FlexReport添加了FlexChart,但FlexChart的数据为后台代码,

     比如List<Point> ptList = new List<Point>() { new Point(1,2), new Point (2,3), new Point(3,4),new Point(4,5),new Point(5,6) },

    请问怎么设置?

5 个回复

倒序浏览
JeffryLI
葡萄城公司职员   /  发表于:2018-10-18 09:31:31
沙发
您好,在DataSource 里面Recordset 这样的属性,可以接受自定性数据对象,但是要实现一个接口
具体请参照
  1. public class MyRecordset: IC1FlexReportRecordset {
  2.   private int _recNo;
  3.   private int _recCount;

  4.   public MyRecordset() {
  5.     _recCount = 60;
  6.   }

  7.   public int RecCount {
  8.     get {
  9.       return _recCount;
  10.     }
  11.     set {
  12.       _recCount = value;
  13.     }
  14.   }

  15.   // IC1FlexReportRecordset implementation
  16.   public string[] GetFieldNames() {
  17.     return new string[] {
  18.       "ID",
  19.       "Caption"
  20.     };
  21.   }

  22.   public Type[] GetFieldTypes() {
  23.     return new Type[] {
  24.       typeof(int), typeof(string)
  25.     };
  26.   }

  27.   public object GetFieldValue(int fieldIndex) {
  28.     switch (fieldIndex) {
  29.       case 0:
  30.         return _recNo + 1;
  31.       case 1:
  32.         return string.Format("Caption {0}", _recNo + 1);
  33.       default:
  34.         return null;
  35.     }
  36.   }

  37.   public bool BOF() {
  38.     return _recNo < 0;
  39.   }

  40.   public bool EOF() {
  41.     return _recNo >= _recCount;
  42.   }

  43.   public void MoveFirst() {
  44.     _recNo = 0;
  45.   }

  46.   public void MoveLast() {
  47.     _recNo = _recCount - 1;
  48.   }

  49.   public void MovePrevious() {
  50.     --_recNo;
  51.   }

  52.   public void MoveNext() {
  53.     ++_recNo;
  54.   }

  55.   public int GetBookmark() {
  56.     return _recNo;
  57.   }

  58.   public void SetBookmark(int bkmk) {
  59.     _recNo = bkmk;
  60.   }

  61.   public int Count {
  62.     get {
  63.       return RecCount;
  64.     }
  65.   }

  66. }

  67. private IC1FlexReportRecordset GetMyCustomDataSource() {
  68.   return new MyRecordset() {
  69.     RecCount = 3
  70.   };
  71. }

  72. private void btnGet_Click(object sender, EventArgs e)
  73. {
  74.   // get custom data source object
  75.   IC1FlexReportRecordset rs = GetMyCustomDataSource();

  76.   // load report definition (before setting the data source)
  77.   rep.Load(@"..\..\Products Report.flxr", "Products Report");

  78.   // use custom data source object in C1FlexReport component
  79.   rep.DataSource.Recordset = rs;

  80.   PdfFilter pf = new PdfFilter();
  81.   pf.Preview = true;
  82.   pf.FileName = @"..\..\Products Report.pdf";
  83.   rep.RenderToFilter(pf);
  84. }
复制代码

这是一种方案,
还有一种方案就是直接将list转化成dataSource,直接用更为方便

评分

参与人数 1满意度 +5 收起 理由
安心海叶 + 5

查看全部评分

请点击评分,对我5分评价,谢谢!

葡萄城控件服务团队
官方网站: https://www.grapecity.com.cn/developer
回复 使用道具 举报
安心海叶
中级会员   /  发表于:2018-10-18 15:55:07
板凳
JeffryLI 发表于 2018-10-18 09:31
您好,在DataSource 里面Recordset 这样的属性,可以接受自定性数据对象,但是要实现一个接口
具体请参照
...

请问List<Category>怎么与FlexChart的数据怎么对应?
回复 使用道具 举报
JeffryLI
葡萄城公司职员   /  发表于:2018-10-19 15:03:52
地板
这个在我们的目录下很多参考的代码  \Documents\ComponentOne Samples\WPF\C1.WPF.FlexChart,请参照
请点击评分,对我5分评价,谢谢!

葡萄城控件服务团队
官方网站: https://www.grapecity.com.cn/developer
回复 使用道具 举报
安心海叶
中级会员   /  发表于:2018-10-22 14:04:00
5#
JeffryLI 发表于 2018-10-19 15:03
这个在我们的目录下很多参考的代码  \Documents\ComponentOne Samples\WPF\C1.WPF.FlexChart,请参照

FlexReport里的FlexChart与C1FlexChart有区别的吧?

现在FlexReport里的内容一部分基础数据来自数据库,比方说Binding代码里的CategoryID和CategoryName,而另一部分FlexChart数据来自后台List<Category>,请问怎么设置?
回复 使用道具 举报
JeffryLI
葡萄城公司职员   /  发表于:2018-10-22 14:28:32
6#
您好,
1、首先flexreport 已经代替了原来的report,所以官方建议是在flexreport使用flexchart,区别只是两个图表的类型,从目前来看,C1chart支持的类型较多.
2、a)数据库的链接可以直接在设计模板中添加数据源,b)在添加多数据源的时候会提示必须填数据源,所以我们需要手动在.flxr文件中手动添加。这样的话,在后台中获取报表数据源集合,在进行赋值。
希望能帮到您。

评分

参与人数 1满意度 +5 收起 理由
安心海叶 + 5 很给力!

查看全部评分

请点击评分,对我5分评价,谢谢!

葡萄城控件服务团队
官方网站: https://www.grapecity.com.cn/developer
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部