WPF界面開發(fā)工具DevExpress WPF使用教程:創(chuàng)建綁定到數(shù)據(jù)的3D圖表控件(第三部分)
下載DevExpress v20.1完整版 DevExpress v20.1漢化資源獲取
通過DevExpress WPF Controls,您能創(chuàng)建有著強(qiáng)大互動(dòng)功能的XAML基礎(chǔ)應(yīng)用程序,這些應(yīng)用程序?qū)W⒂诋?dāng)代客戶的需求和構(gòu)建未來新一代支持觸摸的解決方案。
在本教程中,您將完成可視化數(shù)據(jù)源所需的步驟。
應(yīng)該執(zhí)行以下步驟,本文我們將為大家介紹3個(gè)步驟及最后結(jié)果,更多完整內(nèi)容歡迎持續(xù)關(guān)注!
- Step 1. 編寫一個(gè)應(yīng)用程序
- Step 2. 為圖表和系列綁定添加數(shù)據(jù)
- Step 3. 配置系列視圖
- 結(jié)果
Step 3. 配置系列視圖
本節(jié)中系列的外觀將被配置,將分配一個(gè)不同的系列視圖。此外,通過點(diǎn)的ColorIndex值對(duì)點(diǎn)進(jìn)行著色的著色器將用于提供顏色。
- 打開Series Collection Editor然后選擇Series3D,找到Series3DBase.View屬性并將其設(shè)置為Point3DSeriesView.。
展開視圖屬性,找到Marker3DSeriesView.MarkerModel屬性并將其分配給SphereMarker3DModel對(duì)象。
然后,展開model屬性,并將其 Marker3DSpherePointModel.SphereDetalizationLevel 屬性設(shè)置為L(zhǎng)ow,這將提高應(yīng)用程序性能。
- 找到Series3DViewBase.Colorizer 屬性并將其設(shè)置為RangeColorizer3D。
擴(kuò)展著色器的屬性并將其RangeColorizer3D.RangeStops設(shè)置為-0.4 0.4 1.8 2。
將YellowPalette對(duì)象指定為PaletteColorizer3DBase.Palette屬性值。
將 RangeColorizer3D.ApproximateColors 設(shè)置為true。
最后,將RangeColorizer3D.ValueProvider設(shè)置為新的ColorObjectValueProvider3D對(duì)象,然后單擊OK關(guān)閉編輯器并保存更改。
當(dāng)前,該系列的XAML標(biāo)記應(yīng)如下所示。
<dxc:Series3D DisplayName="Series 1"> <dxc:Series3D.View> <dxc:Point3DSeriesView> <dxc:Point3DSeriesView.MarkerModel> <dxc:Marker3DSpherePointModel SphereDetalizationLevel="Low"/> </dxc:Point3DSeriesView.MarkerModel> <dxc:Point3DSeriesView.Colorizer> <dxc:RangeColorizer3D RangeStops="-0.4 0.4 1.8 2" ApproximateColors="True"> <dxc:RangeColorizer3D.ValueProvider> <dxc:ColorObjectValueProvider3D/> </dxc:RangeColorizer3D.ValueProvider> <dxc:RangeColorizer3D.Palette> <dxc:YellowPalette/> </dxc:RangeColorizer3D.Palette> </dxc:RangeColorizer3D> </dxc:Point3DSeriesView.Colorizer> </dxc:Point3DSeriesView> </dxc:Series3D.View> <!--Point Source Configuration --> </dxc:Series3D>
結(jié)果
下圖演示了已啟動(dòng)的應(yīng)用程序。
以下代碼是本入門課程的結(jié)果。
Star.cs
namespace GettingStarted2 { public class 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; } } }
StarDataViewModel.cs
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<Star> Stars { get; private set; }
public StarStatisticsViewModel() {
Stars = StarStatisticsLoader.Load("/Data/starsdata.csv");
}
}
static class StarStatisticsLoader {
public static IEnumerable<Star> Load(string filepath) {
StreamResourceInfo streamInfo = Application.GetResourceStream(
new Uri(filepath, UriKind.RelativeOrAbsolute)
);
StreamReader reader = new StreamReader(streamInfo.Stream);
Collection<Star> stars = new Collection<Star>();
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;
}
}
}
StarDataViewModel.vb
Imports System.Collections.ObjectModel Imports System.Globalization Imports System.IO Imports System.Windows.Resources Public Class StarDataViewModel Dim mStars As IEnumerable(Of Star) Public ReadOnly Property Stars As IEnumerable(Of Star) Get Return mStars End Get End Property Public Sub New() mStars = StarStatisticsLoader.Load("/Data/starsdata.csv") End Sub End Class Public Module StarStatisticsLoader Public 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 While Return stars End Function End Module
Star.vb
Public Class Star Dim mHipID As Int32 Dim mSpectr As String Dim mX, mY, mZ, mLuminocity, mColorIndex As Double Public ReadOnly Property HipID() As Int32 Get Return mHipID End Get End Property Public ReadOnly Property Spectr() As String Get Return mSpectr End Get End Property Public ReadOnly Property X() As Double Get Return mX End Get End Property Public ReadOnly Property Y() As Double Get Return mY End Get End Property Public ReadOnly Property Z() As Double Get Return mZ End Get End Property Public ReadOnly Property Luminocity() As Double Get Return mLuminocity End Get End Property Public ReadOnly Property ColorIndex() As Double Get Return mColorIndex End Get End Property Public 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 = id mX = x mY = y mZ = z mSpectr = spectr mLuminocity = luminocity mColorIndex = colorIndex End Sub End Class
MainWindow.xaml(C#)
<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:GettingStarted2" xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts" x:Class="GettingStarted2.MainWindow" mc:Ignorable="d" Title="MainWindow" Height="720" Width="1280"> <Window.DataContext> <local:StarStatisticsViewModel/> </Window.DataContext> <Grid> <dxc:Chart3DControl> <dxc:Chart3DControl.Legends> <dxc:Legend/> </dxc:Chart3DControl.Legends> <dxc:Series3DStorage> <dxc:Series3D DisplayName="Series 1"> <dxc:Series3D.View> <dxc:Point3DSeriesView> <dxc:Point3DSeriesView.MarkerModel> <dxc:Marker3DSpherePointModel SphereDetalizationLevel="Low"/> </dxc:Point3DSeriesView.MarkerModel> <dxc:Point3DSeriesView.Colorizer> <dxc:RangeColorizer3D RangeStops="-0.4 0.4 1.8 2" ApproximateColors="True"> <dxc:RangeColorizer3D.ValueProvider> <dxc:ColorObjectValueProvider3D/> </dxc:RangeColorizer3D.ValueProvider> <dxc:RangeColorizer3D.Palette> <dxc:YellowPalette/> </dxc:RangeColorizer3D.Palette> </dxc:RangeColorizer3D> </dxc:Point3DSeriesView.Colorizer> </dxc:Point3DSeriesView> </dxc:Series3D.View> <dxc:SeriesPoint3DDataSourceAdapter DataSource="{Binding Stars}" XArgumentDataMember="X" YArgumentDataMember="Y" ValueDataMember="Z" ColorDataMember="ColorIndex"/> </dxc:Series3D> </dxc:Series3DStorage> </dxc:Chart3DControl> </Grid> </Window>
MainWindow.xaml(VB.NET)
<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:GettingStarted2" xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts" x:Class="GettingStarted2.MainWindow" mc:Ignorable="d" Title="MainWindow" Height="720" Width="1280"> <Window.DataContext> <local:StarDataViewModel/> </Window.DataContext> <Grid> <dxc:Chart3DControl> <dxc:Chart3DControl.Legends> <dxc:Legend/> </dxc:Chart3DControl.Legends> <dxc:Series3DStorage> <dxc:Series3D DisplayName="Series 1"> <dxc:Series3D.View> <dxc:Point3DSeriesView> <dxc:Point3DSeriesView.MarkerModel> <dxc:Marker3DSpherePointModel SphereDetalizationLevel="Low"/> </dxc:Point3DSeriesView.MarkerModel> <dxc:Point3DSeriesView.Colorizer> <dxc:RangeColorizer3D RangeStops="-0.4 0.4 1.8 2" ApproximateColors="True"> <dxc:RangeColorizer3D.ValueProvider> <dxc:ColorObjectValueProvider3D/> </dxc:RangeColorizer3D.ValueProvider> <dxc:RangeColorizer3D.Palette> <dxc:YellowPalette/> </dxc:RangeColorizer3D.Palette> </dxc:RangeColorizer3D> </dxc:Point3DSeriesView.Colorizer> </dxc:Point3DSeriesView> </dxc:Series3D.View> <dxc:SeriesPoint3DDataSourceAdapter DataSource="{Binding Stars}" XArgumentDataMember="X" YArgumentDataMember="Y" ValueDataMember="Z" ColorDataMember="ColorIndex"/> </dxc:Series3D> </dxc:Series3DStorage> </dxc:Chart3DControl> </Grid> </Window>
上DevExpress中文網(wǎng),獲取第一手最新產(chǎn)品資訊!
DevExpress技術(shù)交流群2:775869749 歡迎一起進(jìn)群討論