2017-11-22 31 views

答えて

1

カスタムAxisLabelStyleConverter使用:XAML

enter image description here

を:

<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:WpfApp87" 
     xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" 
     x:Class="WpfApp87.MainWindow" 
     mc:Ignorable="d" 
     Title="MainWindow" Height="475" Width="525"> 

    <Window.Resources> 
     <local:ValueToExponentialConverter x:Key="conv1"/> 
    </Window.Resources> 

    <Grid> 

     <chartingToolkit:Chart Title="Sample Chart"> 
      <chartingToolkit:Chart.DataContext> 
       <PointCollection> 
        <Point X="1" Y="-0.010"/> 
        <Point X="2" Y="-0.008"/> 
        <Point X="3" Y="-0.006"/> 
        <Point X="4" Y="-0.004"/> 
        <Point X="5" Y="-0.002"/> 
        <Point X="6" Y="0.0"/> 
        <Point X="7" Y="0.002"/> 
        <Point X="8" Y="0.004"/> 
        <Point X="9" Y="0.006"/> 
        <Point X="10" Y="0.008"/> 
        <Point X="11" Y="0.010"/> 
        <Point X="12" Y="0.012"/> 
        <Point X="13" Y="0.014"/> 
        <Point X="14" Y="0.016"/> 
        <Point X="15" Y="0.018"/> 
        <Point X="16" Y="0.020"/> 
       </PointCollection> 
      </chartingToolkit:Chart.DataContext> 
      <chartingToolkit:Chart.Axes> 
       <chartingToolkit:LinearAxis Orientation="Y" 
              Location="Left" 
              Interval="0.002" 
              Minimum="-0.01" 
              Maximum="0.02" 
              ShowGridLines="True"> 
        <chartingToolkit:LinearAxis.AxisLabelStyle> 
         <Style TargetType="chartingToolkit:AxisLabel"> 
          <Setter Property="StringFormat" Value="{Binding Converter={StaticResource conv1}}"/> 
          <Setter Property="FontSize" Value="14"/> 
         </Style> 
        </chartingToolkit:LinearAxis.AxisLabelStyle> 
       </chartingToolkit:LinearAxis> 
      </chartingToolkit:Chart.Axes> 
      <chartingToolkit:ColumnSeries DependentValuePath="Y" 
              IndependentValuePath="X" 
              ItemsSource="{Binding}"/> 
     </chartingToolkit:Chart> 

    </Grid> 
</Window> 

コンバータ:

public class ValueToExponentialConverter : IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
     double d = (double)value; 

     if (d == 0 || 0.0099 < d) 
      return Math.Round(d, 3).ToString(); 
     else return d.ToString("0.#E+0"); 
    } 

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
     throw new NotImplementedException(); 
    } 

} 
+1

おかげで多くの!これは完全に問題に答える! – user2784281

+0

@ user2784281:大歓迎です! – jsanalytics

関連する問題