wpf 大数据界面_24小时删!WPF 界面开发可视化数据源500行代码分享
通過DevExpress WPF Controls,您能創建有著強大互動功能的XAML基礎應用程序,這些應用程序專注于當代客戶的需求和構建未來新一代支持觸摸的解決方案。
在本教程中,您將完成可視化數據源所需的步驟。
應該執行以下步驟,本文我們將為大家介紹3個步驟及最后結果,更多完整內容歡迎持續關注!
- Step 1. 編寫一個應用程序
- Step 2. 為圖表和系列綁定添加數據
- Step 3. 配置系列視圖
- 結果
Step 1. 編寫一個應用程序
您將帶有Model和ViewModel類的數據文件添加到項目中。
- 運行MS Visual Studio 2010、2012、2013或2015。
- 創建一個全新的WPF Application項目
- 添加一個新的模型類。 為此,在解決方案資源管理器中右鍵單擊該項目。從invoked菜單中,選擇Add | New Item... element。
在調用的Add New Item對話框中,選擇Code組,然后從項目列表中選擇Class,將文件名設置為Star.cs,然后單擊OK。
- 將添加的文件包含的代碼替換為以下代碼,該代碼描述此入門課程中使用的模型對象。
C#
namespace GettingStarted2 {public struct Star {public int HipID { get; private set; }public string Spectr { get; private set; }public double Luminocity { get; private set; }public double ColorIndex { get; private set; }public double X { get; private set; }public double Y { get; private set; }public double Z { get; private set; }public Star(int id,double x,double y,double z,string spectr, double luminocity, double colorIndex) {HipID = id;X = x;Y = y;Z = z;Spectr = spectr;Luminocity = luminocity;ColorIndex = colorIndex;}}}VB.NET
Public Class StarDim mHipID As Int32Dim mSpectr As StringDim mX, mY, mZ, mLuminocity, mColorIndex As DoublePublic ReadOnly Property HipID() As Int32GetReturn mHipIDEnd GetEnd PropertyPublic ReadOnly Property Spectr() As StringGetReturn mSpectrEnd GetEnd PropertyPublic ReadOnly Property X() As DoubleGetReturn mXEnd GetEnd PropertyPublic ReadOnly Property Y() As DoubleGetReturn mYEnd GetEnd PropertyPublic ReadOnly Property Z() As DoubleGetReturn mZEnd GetEnd PropertyPublic ReadOnly Property Luminocity() As DoubleGetReturn mLuminocityEnd GetEnd PropertyPublic ReadOnly Property ColorIndex() As DoubleGetReturn mColorIndexEnd GetEnd PropertyPublic Sub New(ByVal id As Int32,ByVal x As Double,ByVal y As Double,ByVal z As Double,ByVal spectr As String,ByVal luminocity As Double,ByVal colorIndex As Double)mHipID = idmX = xmY = ymZ = zmSpectr = spectrmLuminocity = luminocitymColorIndex = colorIndexEnd SubEnd Class- 將數據文件添加到項目中。 將DevExpress Charts Demo隨附的stardata.csv文件復制到項目目錄新創建的Data目錄中。
注意:默認情況下,該文件位于C:甥敳獲PublicDocumentsDevExpress Demos 20.1ComponentsWPFCSChartsDemo.WpfData目錄中。
在解決方案資源管理器中,切換Show All Files按鈕,然后右鍵單擊Data目錄。從調用的菜單中,選擇Include In Project。
單擊解決方案資源管理器中的stardata.csv文件,然后在Properties窗口中,將Build Action屬性設置為Resource。
- ViewModel應該從數據文件加載模型對象,像以前一樣,將文件添加到ViewModel的項目中。
用以下代碼替換新文件中的代碼。
C#
using System;using System.Collections.Generic;using System.Collections.ObjectModel;using System.Globalization;using System.IO;using System.Windows;using System.Windows.Resources;namespace GettingStarted2 {public class StarStatisticsViewModel {public IEnumerable Stars { get; }public StarStatisticsViewModel() {Stars = StarStatisticsLoader.Load("/Data/starsdata.csv");}}static class StarStatisticsLoader {public static IEnumerable Load(string filepath) {StreamResourceInfo streamInfo = Application.GetResourceStream(new Uri(filepath, UriKind.RelativeOrAbsolute));StreamReader reader = new StreamReader(streamInfo.Stream);Collection stars = new Collection();while (!reader.EndOfStream) {String dataLine = reader.ReadLine();String[] serializedValues = dataLine.Split(';');stars.Add(new Star(id: Convert.ToInt32(serializedValues[0], CultureInfo.InvariantCulture),x: Convert.ToDouble(serializedValues[3], CultureInfo.InvariantCulture),y: Convert.ToDouble(serializedValues[4], CultureInfo.InvariantCulture),z: Convert.ToDouble(serializedValues[5], CultureInfo.InvariantCulture),spectr: serializedValues[1],luminocity: Convert.ToDouble(serializedValues[6], CultureInfo.InvariantCulture),colorIndex: Convert.ToDouble(serializedValues[2], CultureInfo.InvariantCulture)));}return stars;}}}VB.NET
Imports System.Collections.ObjectModelImports System.GlobalizationImports System.IOImports System.Windows.ResourcesPublic Class StarDataViewModelDim mStars As IEnumerable(Of Star)Public ReadOnly Property Stars As IEnumerable(Of Star)GetReturn mStarsEnd GetEnd PropertyPublic Sub New()mStars = StarStatisticsLoader.Load("/Data/starsdata.csv")End SubEnd ClassPublic Module StarStatisticsLoaderPublic Function Load(ByVal filepath As String) As IEnumerable(Of Star)Dim streamInfo As StreamResourceInfo = Application.GetResourceStream(New Uri(filepath, UriKind.RelativeOrAbsolute))Dim reader As StreamReader = New StreamReader(streamInfo.Stream)Dim stars As Collection(Of Star) = New Collection(Of Star)()While (Not reader.EndOfStream)Dim dataLine As String = reader.ReadLine()Dim serializedValues As String() = dataLine.Split(";")stars.Add(New Star(id:=Convert.ToInt32(serializedValues(0), CultureInfo.InvariantCulture),x:=Convert.ToDouble(serializedValues(3), CultureInfo.InvariantCulture),y:=Convert.ToDouble(serializedValues(4), CultureInfo.InvariantCulture),z:=Convert.ToDouble(serializedValues(5), CultureInfo.InvariantCulture),spectr:=serializedValues(1),luminocity:=Convert.ToDouble(serializedValues(6), CultureInfo.InvariantCulture),colorIndex:=Convert.ToDouble(serializedValues(2), CultureInfo.InvariantCulture)))End WhileReturn starsEnd FunctionEnd Module- 現在,將ViewModel分配給Window.DataContext屬性:選擇Window,找到DataContext屬性,然后單擊New按鈕。在調用的窗口中,選擇GettingStarted.StarDataViewModel類,然后單擊OK。
準備工作完成,這下一篇文章中將詳細說明如何添加Chart3D控件,分配數據和自定義顯示設置。
點擊下方“了解更多”查看當下流行的界面開發組件!
總結
以上是生活随笔為你收集整理的wpf 大数据界面_24小时删!WPF 界面开发可视化数据源500行代码分享的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2022年 Vue 的发展情况报告【整理
- 下一篇: 用Node.js通过sitemap.xm