DevExpress控件使用交流,DevExpress中国社区 售前咨询
当前位置: 首页 > 开发资源 » 示例代码 » DevExpress Dashboard示例代码:处理代码形式的数据源

DevExpress Dashboard示例代码:处理代码形式的数据源

作者:besy   来源:慧都控件网   浏览:Loading...次   发布时间:2013-12-31   评论:0条

仪表盘工具 DevExpress Dashboard 可轻松打造数据可视化企业级仪表盘,且能保证流畅的UI体验和高效的性能。接下来为大家提供一些它的常用示例代码。

假设仪表盘的数据源被部署为代码的形式:

// Obtains the required data from the data store.
// ...

// Creates a data source and adds it to the dashboard.
dashboardDesigner.Dashboard.AddDataSource("Data Source", data);

然后保存仪表盘XML定义,这个定义将只包含数据源名称。若要在运行时应用仪表盘的这些数据,需要处理DataLoading这个事件。

本例中,我们为Cars data table创建了一个数据源,然后通过Dashboard.AddDataSource将它添加到 Dashboard.DataSources 集合中。最后用 DashboardDesigner.DataLoading 事件去处理仪表盘的数据:


using System.Data;
using DevExpress.XtraBars.Ribbon;
using DevExpress.DashboardCommon;

namespace Dashboard_DataLoading {
    public partial class Form1 : RibbonForm {
        public Form1() {
            InitializeComponent();

            //Creates and initializes a Ribbon in the Dashboard Designer's parent control.
            dashboardDesigner1.CreateRibbon();
        }

        // Adds a new data source to the dashboard DataSources collection on the first load and 
        // assigns this dashboard to the DashboardDesigner.Dashboard property.
        private void Form1_Load(object sender, System.EventArgs e) {
            Dashboard dashboard = new Dashboard();
            dashboard.AddDataSource("Data Source 1", GetData());
            dashboardDesigner1.Dashboard = dashboard;
        }

        // Handles the DashboardDesigner.DataLoading event to supply a dashboard with data.
        private void dashboardDesigner1_DataLoading(object sender,
            DevExpress.DataAccess.DataLoadingEventArgs e) {
                if (e.DataSourceName == "Data Source 1") {

                //Specifies data for the required data source as a data table.
                e.Data = GetData();
            }
        }

        // Creates a new data set, fills it with data from the XML file and returns a data set table.
        public DataTable GetData() {
            DataSet xmlDataSet = new DataSet();
            xmlDataSet.ReadXml(@"..\..\Data\Cars.xml");
            return xmlDataSet.Tables["Cars"];
        }
    }
}


本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [http://www.devexpresscn.com/]
本文地址:http://www.devexpresscn.com/Resources/CodeExamples-402.html

评论列表

暂无评论

请谈谈你的看法 请使用IE或者Firefox浏览器,暂不支持Chrome!

昵称 不填则默认为游客评论

DevExpress DXperience DXv2 v12

DevExpress DXperience 下载 download

DevExpress购买、价格、授权

慧都控件网为DevExpress界面控件的中国地区唯一正式授权经销商,正版控件销售公司,授权代理商,经销商及合作伙伴。

电话:400-700-1020
        023-66090381

邮箱:sales@evget.com

>>如何选择正规控件购买渠道

相关资源