Thursday 31 March 2011

how to disable X or Y Axis in Silverlight Chart control

when working on Silverlight Toolkit Chart controls, sometimes I want to disable X or Y Axis,
like this:


As you can see, I just want to show the content of the chart, after searching for a while, I found the solution like this:




   1:  <navigation:Page x:Class="ShangHaiDataShow.Views.DataShow" 
   2:             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
   3:             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
   4:             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
   5:             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
   6:             mc:Ignorable="d"
   7:             xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
   8:             d:DesignWidth="640" d:DesignHeight="480"
   9:             Title="DataShow Page" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit">
  10:      <Grid x:Name="LayoutRoot">
  11:          <toolkit:Chart Title="Chart Title">
  12:              <toolkit:Chart.Axes>
  13:                  <toolkit:LinearAxis Orientation="X" ShowGridLines="False">
  14:                      <toolkit:LinearAxis.MajorTickMarkStyle>
  15:                          <Style TargetType="Line">
  16:                              <Setter Property="Stroke" Value="White"/>
  17:                          </Style>
  18:                      </toolkit:LinearAxis.MajorTickMarkStyle>
  19:                      <toolkit:LinearAxis.AxisLabelStyle>
  20:                          <Style TargetType="toolkit:AxisLabel">
  21:                              <Setter Property="Template" Value="x:Null" />
  22:                          </Style>
  23:                      </toolkit:LinearAxis.AxisLabelStyle>
  24:                  </toolkit:LinearAxis>
  25:   
  26:                  <toolkit:LinearAxis Orientation="Y" ShowGridLines="False">
  27:                      <toolkit:LinearAxis.MajorTickMarkStyle>
  28:                          <Style TargetType="Line">
  29:                              <Setter Property="Stroke" Value="Red"/>
  30:                          </Style>
  31:                      </toolkit:LinearAxis.MajorTickMarkStyle>
  32:                      <toolkit:LinearAxis.AxisLabelStyle>
  33:                          <Style TargetType="toolkit:AxisLabel">
  34:                              <Setter Property="Template" Value="x:Null" />
  35:                          </Style>
  36:                      </toolkit:LinearAxis.AxisLabelStyle>
  37:                  </toolkit:LinearAxis>
  38:              </toolkit:Chart.Axes>
  39:              <toolkit:Chart.Series>
  40:                  
  41:                  <toolkit:ScatterSeries Title="P Levels" 
  42:                                         ItemsSource="{Binding Path=DeviceDatas}"
  43:                                         IndependentValueBinding="{Binding Path=Location}"
  44:                                         DependentValueBinding="{Binding Path=TheValue}"
  45:                                           
  46:                                         />
  47:              </toolkit:Chart.Series>
  48:              
  49:          </toolkit:Chart>
  50:      </Grid>
  51:  </navigation:Page>