翻譯|使用教程|編輯:龔雪|2020-11-16 11:23:17.900|閱讀 354 次
概述:通過DevExpress WPF Controls,您能創(chuàng)建有著強(qiáng)大互動(dòng)功能的XAML基礎(chǔ)應(yīng)用程序。本文將為大家介紹使用自動(dòng)生成的序列創(chuàng)建3D圖表,DevExpress WPF v20.2震撼,歡迎下載體驗(yàn)新版!
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
下載DevExpress v20.2完整版 DevExpress v20.1漢化資源獲取
通過DevExpress WPF Controls,您能創(chuàng)建有著強(qiáng)大互動(dòng)功能的XAML基礎(chǔ)應(yīng)用程序,這些應(yīng)用程序?qū)W⒂诋?dāng)代客戶的需求和構(gòu)建未來新一代支持觸摸的解決方案。
本教程將指導(dǎo)您完成根據(jù)基礎(chǔ)數(shù)據(jù)源自動(dòng)創(chuàng)建3D系列所需的步驟。
應(yīng)該執(zhí)行以下步驟,本文我們將為大家介紹3個(gè)步驟及最后結(jié)果,更多完整內(nèi)容歡迎持續(xù)關(guān)注!
在此步驟中,您將學(xué)習(xí)如何配置外觀圖設(shè)置,為此請(qǐng)按照以下步驟操作。
完成上述所有步驟后,您的代碼將顯示如下。
IriesViewModel.cs
using System; using System.Collections.ObjectModel; using System.Windows; using System.Windows.Resources; using System.Xml.Linq; namespace Chart3D_Lesson3 { public class IrisesViewModel { public ObservableCollection<IrisData> Irises { get; set; } public IrisesViewModel() { this.Irises = DataLoader.GetIrises("/Data/IrisDataSet.xml"); } } static class DataLoader { public static ObservableCollection<IrisData> GetIrises(string filepath) { ObservableCollection<IrisData> irisDataSet = new ObservableCollection<IrisData>(); Uri uri = new Uri(filepath, UriKind.RelativeOrAbsolute); StreamResourceInfo info = Application.GetResourceStream(uri); XDocument document = XDocument.Load(info.Stream); if (document == null) return irisDataSet; foreach (XElement element in document.Element("IrisDataSet").Elements("IrisData")) { double sepalLength = Convert.ToDouble(element.Element("SepalLength").Value); double sepalWidth = Convert.ToDouble(element.Element("SepalWidth").Value); double petalLength = Convert.ToDouble(element.Element("PetalLength").Value); double petalWidth = Convert.ToDouble(element.Element("PetalWidth").Value); string species = element.Element("Species").Value.ToString(); irisDataSet.Add(new IrisData(species, sepalWidth, sepalLength, petalWidth, petalLength)); } return irisDataSet; } } }
Iris.cs
namespace Chart3D_Lesson3 { public class IrisData { public string Species { get; private set; } public double SepalWidth { get; private set; } public double SepalLength { get; private set; } public double PetalWidth { get; private set; } public double PetalLength { get; private set; } public IrisData( string species, double sepalWidth, double sepalLength, double petalWidth, double petalLength ) { Species = species; SepalWidth = sepalWidth; SepalLength = sepalLength; PetalWidth = petalWidth; PetalLength = petalLength; } } }
IrisesViewModel.vb
Imports System Imports System.Collections.ObjectModel Imports System.Windows Imports System.Windows.Resources Imports System.Xml.Linq Namespace Chart3D_Lesson3 Public Class IrisesViewModel Public Property Irises() As ObservableCollection(Of IrisData) Public Sub New() Me.Irises = DataLoader.GetIrises("/Data/IrisDataSet.xml") End Sub End Class Friend NotInheritable Class DataLoader Private Sub New() End Sub Public Shared Function GetIrises(ByVal filepath As String) As ObservableCollection(Of IrisData) Dim irisDataSet As New ObservableCollection(Of IrisData)() Dim uri As New Uri(filepath, UriKind.RelativeOrAbsolute) Dim info As StreamResourceInfo = Application.GetResourceStream(uri) Dim document As XDocument = XDocument.Load(info.Stream) If document Is Nothing Then Return irisDataSet End If For Each element As XElement In document.Element("IrisDataSet").Elements("IrisData") Dim sepalLength As Double = Convert.ToDouble(element.Element("SepalLength").Value) Dim sepalWidth As Double = Convert.ToDouble(element.Element("SepalWidth").Value) Dim petalLength As Double = Convert.ToDouble(element.Element("PetalLength").Value) Dim petalWidth As Double = Convert.ToDouble(element.Element("PetalWidth").Value) Dim species As String = element.Element("Species").Value.ToString() irisDataSet.Add(New IrisData(species, sepalWidth, sepalLength, petalWidth, petalLength)) Next element Return irisDataSet End Function End Class End Namespace
Iris.vb
Namespace Chart3D_Lesson3 Public Class IrisData Private privateSpecies As String Public Property Species() As String Get Return privateSpecies End Get Private Set(ByVal value As String) privateSpecies = value End Set End Property Private privateSepalWidth As Double Public Property SepalWidth() As Double Get Return privateSepalWidth End Get Private Set(ByVal value As Double) privateSepalWidth = value End Set End Property Private privateSepalLength As Double Public Property SepalLength() As Double Get Return privateSepalLength End Get Private Set(ByVal value As Double) privateSepalLength = value End Set End Property Private privatePetalWidth As Double Public Property PetalWidth() As Double Get Return privatePetalWidth End Get Private Set(ByVal value As Double) privatePetalWidth = value End Set End Property Private privatePetalLength As Double Public Property PetalLength() As Double Get Return privatePetalLength End Get Private Set(ByVal value As Double) privatePetalLength = value End Set End Property Public Sub New(ByVal species As String, ByVal sepalWidth As Double, ByVal sepalLength As Double, ByVal petalWidth As Double, ByVal petalLength As Double) Me.Species = species Me.SepalWidth = sepalWidth Me.SepalLength = sepalLength Me.PetalWidth = petalWidth Me.PetalLength = petalLength End Sub End Class End Namespace
MainWindow.xaml
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:Chart3D_Lesson3" xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts" x:Class="Chart3D_Lesson3.MainWindow" mc:Ignorable="d" Title="MainWindow" Height="350" Width="525"> <Window.DataContext> <local:IrisesViewModel/> </Window.DataContext> <Grid> <dxc:Chart3DControl> <dxc:Chart3DControl.Legends> <dxc:Legend BorderBrush="Transparent" Background="Transparent"/> </dxc:Chart3DControl.Legends> <dxc:Series3DDataSourceAdapter DataSource="{Binding Irises}" XArgumentDataMember="SepalLength" YArgumentDataMember="PetalLength" ValueDataMember="SepalWidth" SeriesDataMember="Species" dxc:Bubble3DSeriesView.WeightDataMember="PetalWidth" > <dxc:Series3DDataSourceAdapter.SeriesTemplate> <dxc:Series3DTemplate> <dxc:Series3DTemplate.View> <dxc:Bubble3DSeriesView MaxSize="0.5" MinSize="0.1"> <dxc:Bubble3DSeriesView.MarkerModel> <dxc:Marker3DSpherePointModel/> </dxc:Bubble3DSeriesView.MarkerModel> </dxc:Bubble3DSeriesView> </dxc:Series3DTemplate.View> </dxc:Series3DTemplate> </dxc:Series3DDataSourceAdapter.SeriesTemplate> </dxc:Series3DDataSourceAdapter> </dxc:Chart3DControl> </Grid> </Window>
運(yùn)行項(xiàng)目以查看結(jié)果,下圖顯示了應(yīng)用程序運(yùn)行時(shí)的結(jié)果圖表。
DevExpress技術(shù)交流群2:775869749 歡迎一起進(jìn)群討論
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都網(wǎng)