Jump to content
Software FX Community

mrsim00

Members
  • Posts

    2
  • Joined

  • Last visited

mrsim00's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. hi~. I'm tring to using Surfacechart Control with pointlabel diplay some other value. So I create datatemplate to change pointlabel sharpe. but datatemplate does not work. when i use my datetemplate in barChart, it work as my expect.! I attached source code . Please Help me~ [Window1.xaml] <Window x:Class="SurfaceChart.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:cfx="http://schemas.softwarefx.com/chartfx/wpf/80" Title="Chart FX for WPF - Surface Chart" Height="800" Width="798" Loaded="Window_Loaded"> <Window.Resources> <DataTemplate x:Key="itemTemplate"> <StackPanel Orientation="Horizontal" Margin="0,0,0,50"> <Polyline Fill="{x:Static Brushes.Gold}" Points="18,0 21,13 35,12 23,20 28,33 18,23 7,33 12,20 0,12 14,13" /> <StackPanel> <Label FontSize="12" FontWeight="Bold" Content="{Binding Path=DataItem.idValue}" /> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Path=DataItem.xValue}" /> <TextBlock Text=": "/> <TextBlock Text="{Binding Path=DataItem.yValue}" /> </StackPanel> </StackPanel> </StackPanel> </DataTemplate> </Window.Resources> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> <RowDefinition Height="*" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Grid Grid.Row="0"> <!--Description Area--> <Border Margin="2" BorderBrush="Gainsboro" CornerRadius="6" BorderThickness="4"> <Grid> <TextBlock TextWrapping="Wrap" TextAlignment="Left" Margin="5" FontFamily="Veranda"> A surface plot is a 3D chart displaying data plotted over a surface area. A contour chart is normally a 2D representation of a surface chart. Surface and contour charts are suitable for comparing two groups of data combinations.</TextBlock> </Grid> </Border> </Grid> <Grid Grid.Row="1"> <!--Controls Area--> <Border Margin="2" BorderBrush="Gainsboro" CornerRadius="6" BorderThickness="4" > <StackPanel> <StackPanel Orientation="Horizontal" > <GroupBox Header="Type of Chart" Height="80" Width="100" Margin="2"> <StackPanel> <RadioButton Name="radioButtonSurface" IsChecked="True">Surface</RadioButton> <RadioButton Name="radioButtonContour">Countour</RadioButton> </StackPanel> </GroupBox> <GroupBox Header="Options" Height="80" Width="300" Margin="2"> <StackPanel Orientation="Horizontal"> <StackPanel> <CheckBox Name="checkBoxShowPointsGridlines" Margin="2" VerticalAlignment="Center" IsChecked="True">Show Points Gridlines</CheckBox> <CheckBox Name="checkBoxShowSeriesGridlines" Margin="2" VerticalAlignment="Center" IsChecked="True">Show Series Gridlines</CheckBox> </StackPanel> <StackPanel> <CheckBox Name="checkBoxShowContourLines" Margin="2" VerticalAlignment="Center" IsChecked="True">Show Contour Lines</CheckBox> <CheckBox Name="checkBoxBottomEffect" Margin="2" VerticalAlignment="Center" IsChecked="True">Bottom Effect</CheckBox> </StackPanel> </StackPanel> </GroupBox> <GroupBox Header="Fill" Height="80" Width="150" Margin="2"> <StackPanel> <RadioButton Name="radioButtonSolidBrush" Margin="2" VerticalAlignment="Center" IsChecked="True">One Solid Brush</RadioButton> <RadioButton Name="radioButtonSolidBrushes" Margin="2" VerticalAlignment="Center">Many Solid Brushes</RadioButton> <RadioButton Name="radioButtonGradientBrush" Margin="2" VerticalAlignment="Center">Gradient Brush</RadioButton> </StackPanel> </GroupBox> </StackPanel> </StackPanel> </Border> </Grid> <Grid Grid.Row="2"> <cfx:Chart x:Name="chart1" Margin="2" /> </Grid> </Grid> </Window> [ Window1.xaml.cs] using System; using System.IO; using System.Linq; using System.Windows; using System.Xml.Linq; using ChartFX.WPF; using ChartFX.WPF.Data; using System.Windows.Media; using ChartFX.WPF.Galleries; using System.Windows.Controls; using System.Windows.Media.Imaging; using System.Windows.Media.Media3D; using ChartFX.WPF.Annotation; namespace SurfaceChart { /// <summary> /// Interaction logic for Window1.xaml /// </summary> public partial class Window1 : Window { ChartFX.WPF.LightCollection originalLights; Surface surface; public Window1() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { XDocument xmlDoc = XDocument.Load(Directory.GetCurrentDirectory() + "\\Resources\\SurfaceData.xml"); var data = from points in xmlDoc.Descendants("Point") select new { xValue = points.Attribute("X").Value, yValue = points.Attribute("Y").Value, zValue = points.Attribute("Z").Value, idValue = points.Attribute("ID").Value, }; DataTemplate dataTemplate = (DataTemplate)this.FindResource("itemTemplate"); chart1.Visibility = System.Windows.Visibility.Visible; chart1.ItemsSource = data; chart1.AllSeries.PointLabels.Template = dataTemplate; chart1.AllSeries.PointLabels.Visibility = System.Windows.Visibility.Visible; chart1.AllSeries.PointLabels.Anchor = PointLabelAnchor.Value; chart1.AllSeries.PointLabels.FontSize = 8; CrosstabTransform ct = new CrosstabTransform(); ct.RowPath = "yValue"; ct.ColumnPath = "xValue"; ct.ValuePath = "zValue"; chart1.DataTransforms.Add(ct); chart1.Gallery = Gallery.Surface; chart1.View3D.IsEnabled = true; chart1.AxisX.ForceZero = false; chart1.AxisY.ForceZero = false; surface = (Surface)chart1.AllSeries.GalleryAttributes; //chart1.Series.First().Marker.Visibility = System.Windows.Visibility.Visible; originalLights = chart1.View3D.Lights; checkBoxBottomEffect.Checked += new RoutedEventHandler(checkBoxsShowHide_Checked); checkBoxShowContourLines.Checked += new RoutedEventHandler(checkBoxsShowHide_Checked); checkBoxShowPointsGridlines.Checked += new RoutedEventHandler(checkBoxsShowHide_Checked); checkBoxShowSeriesGridlines.Checked += new RoutedEventHandler(checkBoxsShowHide_Checked); checkBoxBottomEffect.Unchecked += new RoutedEventHandler(checkBoxsShowHide_Unchecked); checkBoxShowContourLines.Unchecked += new RoutedEventHandler(checkBoxsShowHide_Unchecked); checkBoxShowPointsGridlines.Unchecked += new RoutedEventHandler(checkBoxsShowHide_Unchecked); checkBoxShowSeriesGridlines.Unchecked += new RoutedEventHandler(checkBoxsShowHide_Unchecked); radioButtonContour.Checked += new RoutedEventHandler(radioButtonContour_Checked); radioButtonSurface.Checked += new RoutedEventHandler(radioButtonSurface_Checked); radioButtonSolidBrush.Checked += new RoutedEventHandler(radioButtonSolidBrush_Checked); radioButtonSolidBrushes.Checked += new RoutedEventHandler(radioButtonSolidBrushes_Checked); radioButtonGradientBrush.Checked += new RoutedEventHandler(radioButtonGradientBrush_Checked); surface.ShowScaleInLegend = false; } void radioButtonSurface_Checked(object sender, RoutedEventArgs e) { View3D view3D = chart1.View3D; view3D.AngleX = 10; view3D.AngleY = 20; view3D.Projection = Projection.Perspective; view3D.BackWallVisibility = Visibility.Visible; chart1.AxisY.Visibility = Visibility.Visible; chart1.AxisX.Line.Visibility = Visibility.Visible; chart1.AxisX.Grids.Major.Visibility = Visibility.Visible; view3D.Lights.Clear(); for (int i = 0; i < originalLights.Count; i++) { view3D.Lights.Add(originalLights); } chart1.View3D.MouseRotate = MouseRotate.Click; } void radioButtonContour_Checked(object sender, RoutedEventArgs e) { ChartBorder child = (ChartBorder) VisualTreeHelper.GetChild(chart1, 0); Grid child1 = (Grid) VisualTreeHelper.GetChild(child, 0); Border child2 = (Border)VisualTreeHelper.GetChild(child1, 0); DependencyObject child3 = VisualTreeHelper.GetChild(child2, 0); originalLights = chart1.View3D.Lights; View3D view3D = chart1.View3D; view3D.AngleX = -90; view3D.AngleY = 0; view3D.Projection = Projection.Orthographic; view3D.BackWallVisibility = Visibility.Collapsed; chart1.AxisY.Visibility = Visibility.Collapsed; chart1.AxisX.Line.Visibility = Visibility.Collapsed; chart1.AxisX.Grids.Major.Visibility = Visibility.Collapsed; view3D.Lights.Clear(); AmbientLight ambLight = new AmbientLight(Color.FromRgb(0xD0, 0xD0, 0xD0)); view3D.Lights.Add(ambLight); chart1.View3D.MouseRotate = MouseRotate.Disabled; } private void checkBoxsShowHide_Unchecked(object sender, RoutedEventArgs e) { switch (((CheckBox)sender).Name) { case "checkBoxBottomEffect": chart1.Series[1].Fill = chart1.Series[0].Fill; break; case "checkBoxShowContourLines": surface.ShowContourLines = false; break; case "checkBoxShowPointsGridlines": surface.ShowPointsGridlines = false; break; case "checkBoxShowSeriesGridlines": surface.ShowSeriesGridlines = false; break; default: break; } } private void checkBoxsShowHide_Checked(object sender, RoutedEventArgs e) { switch (((CheckBox)sender).Name) { case "checkBoxBottomEffect": chart1.Series[1].ClearValue(SeriesAttributes.FillProperty); break; case "checkBoxShowContourLines": surface.ShowContourLines = true; break; case "checkBoxShowPointsGridlines": surface.ShowPointsGridlines = true; break; case "checkBoxShowSeriesGridlines": surface.ShowSeriesGridlines = true; break; default: break; } } private void radioButtonGradientBrush_Checked(object sender, RoutedEventArgs e) { LinearGradientBrush myHorizontalGradient = new LinearGradientBrush(); myHorizontalGradient.StartPoint = new Point(0, 0); myHorizontalGradient.EndPoint = new Point(0, 1); myHorizontalGradient.GradientStops.Add(new GradientStop(Color.FromRgb(0xFF, 0x00, 0x00), 0.0)); myHorizontalGradient.GradientStops.Add(new GradientStop(Color.FromRgb(0xFF, 0x6A, 0x00), 0.2)); myHorizontalGradient.GradientStops.Add(new GradientStop(Color.FromRgb(0xFF, 0xFF, 0x00), 0.4)); myHorizontalGradient.GradientStops.Add(new GradientStop(Color.FromRgb(0x00, 0xFF, 0x00), 0.6)); myHorizontalGradient.GradientStops.Add(new GradientStop(Color.FromRgb(0x00, 0xFF, 0x90), 0.8)); myHorizontalGradient.GradientStops.Add(new GradientStop(Color.FromRgb(0x00, 0xFF, 0x90), 1.0)); chart1.Series[0].Fill = myHorizontalGradient; if (!checkBoxBottomEffect.IsChecked.Value) chart1.Series[1].Fill = myHorizontalGradient; } private void radioButtonSolidBrushes_Checked(object sender, RoutedEventArgs e) { LinearGradientBrush myHorizontalGradient = new LinearGradientBrush(); myHorizontalGradient.StartPoint = new Point(0, 0); myHorizontalGradient.EndPoint = new Point(0, 1); myHorizontalGradient.GradientStops.Add(new GradientStop(Color.FromRgb(0xFF, 0x00, 0x00), 0.0)); myHorizontalGradient.GradientStops.Add(new GradientStop(Color.FromRgb(0xFF, 0x00, 0x00), 0.1999)); myHorizontalGradient.GradientStops.Add(new GradientStop(Color.FromRgb(0xFF, 0x6A, 0x00), 0.2)); myHorizontalGradient.GradientStops.Add(new GradientStop(Color.FromRgb(0xFF, 0x6A, 0x00), 0.3999)); myHorizontalGradient.GradientStops.Add(new GradientStop(Color.FromRgb(0xFF, 0xFF, 0x00), 0.4)); myHorizontalGradient.GradientStops.Add(new GradientStop(Color.FromRgb(0xFF, 0xFF, 0x00), 0.5999)); myHorizontalGradient.GradientStops.Add(new GradientStop(Color.FromRgb(0x00, 0xFF, 0x00), 0.6)); myHorizontalGradient.GradientStops.Add(new GradientStop(Color.FromRgb(0x00, 0xFF, 0x00), 0.7999)); myHorizontalGradient.GradientStops.Add(new GradientStop(Color.FromRgb(0x00, 0xFF, 0x90), 0.8)); myHorizontalGradient.GradientStops.Add(new GradientStop(Color.FromRgb(0x00, 0xFF, 0x90), 1.0)); chart1.Series[0].Fill = myHorizontalGradient; if (!checkBoxBottomEffect.IsChecked.Value) chart1.Series[1].Fill = myHorizontalGradient; } private void radioButtonSolidBrush_Checked(object sender, RoutedEventArgs e) { chart1.Series[0].ClearValue(SeriesAttributes.FillProperty); } } } [surfaceData.xml] <SurfaceData> <Point X="0" Y="0" Z="500" ID="SAMSUNG01" /> <Point X="1" Y="0" Z="15" ID="LG1" /> <Point X="2" Y="0" Z="50" ID="LG2"/> <Point X="3" Y="0" Z="65" ID="LG3"/> <Point X="4" Y="0" Z="5" ID="LG4"/> <Point X="5" Y="0" Z="10" ID="LG5"/> <Point X="6" Y="0" Z="20" ID="LG6"/> <Point X="7" Y="0" Z="15" ID="LG7"/> <Point X="8" Y="0" Z="169" ID="LG8"/> <Point X="9" Y="0" Z="137.5" ID="LG9"/> <Point X="0" Y="1" Z="10.5" ID="LG10"/> <Point X="1" Y="1" Z="20.3" ID="LG11"/> <Point X="2" Y="1" Z="305" ID="LG12"/> <Point X="3" Y="1" Z="137.5" ID="LG13"/> <Point X="4" Y="1" Z="137.6" ID="LG14"/> <Point X="5" Y="1" Z="137.6" ID="LG15"/> <Point X="6" Y="1" Z="137.7" ID="LG16"/> <Point X="7" Y="1" Z="174.3" ID="LG17"/> <Point X="0" Y="2" Z="171.5" ID="LG18"/> <Point X="1" Y="2" Z="137.3" ID="LG19"/> <Point X="2" Y="2" Z="500.5" ID="LG20"/> <Point X="3" Y="2" Z="137.5" ID="LG21"/> <Point X="4" Y="2" Z="137.6" ID="LG22"/> <Point X="5" Y="2" Z="500.6" ID="LG23"/> <Point X="6" Y="2" Z="137.7" ID="LG24"/> <Point X="7" Y="2" Z="137.3" ID="LG25"/> <Point X="0" Y="3" Z="307.5" ID="LG26"/> <Point X="1" Y="3" Z="307.3" ID="LG27"/> <Point X="2" Y="3" Z="500.5" ID="LG28"/> <Point X="3" Y="3" Z="137.5" ID="LG29"/> <Point X="4" Y="3" Z="228.6" ID="LG30"/> <Point X="5" Y="3" Z="500.6" ID="LG31"/> <Point X="6" Y="3" Z="137.7" ID="LG32"/> <Point X="7" Y="3" Z="174.3" ID="LG33"/> <Point X="0" Y="4" Z="174.5" ID="LG34"/> <Point X="1" Y="4" Z="174.3" ID="LG35"/> <Point X="2" Y="4" Z="174.5" ID="LG36"/> <Point X="3" Y="4" Z="404.5" ID="LG37"/> <Point X="4" Y="4" Z="174.6" ID="LG38"/> <Point X="5" Y="4" Z="104.6" ID="LG39"/> <Point X="6" Y="4" Z="74.7" ID="LG40"/> <Point X="7" Y="4" Z="74.3" ID="LG41"/> </SurfaceData>
  2. hi. I'm trying to use surfaceChart with pointlabel diplay not default(zPath) value. So I modified sample source in chart fx examples. When i was use nomal barChart, my template work as my expect, but if i change to surfaceChart datatemplate does not work. Can i get some help? I attached all code ~ (modify charFx Sample Code) [ Window1.xaml] [Windows.cs] [surfaceData.xml]
×
×
  • Create New...