仪表盘工具 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控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/502.html
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/502.html