2012-02-13 14 views
5

He creado un cuadro con el kit de herramientas de gráficos WPF Toolkit (3.5) y no puedo obtener las etiquetas del eje y para mostrar números pequeños (por ejemplo, .001) Establecí los valores mínimos y máximos en .001 y .009 respectivamente para el eje y, y aunque el diagrama es gráficamente correcto, las etiquetas de rango del eje y muestran "0" o ".01". Supongo que esto es una limitación del control de gráfico en el kit de herramientas 3.5, pero espero que me falta algo. Aquí hay un código de ejemplo:Las etiquetas del eje y del juego de herramientas de gráficos WPF aparecen como cero para números pequeños

XAML:

<Window x:Class="WpfChartApplication.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="MainWindow" Height="350" Width="525" 
    xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"> 
<Grid> 
    <chartingToolkit:Chart Name="chart1"> 
     <chartingToolkit:LineSeries 
         Title="Rates" 
         ItemsSource="{Binding Rates}" 
         IndependentValueBinding="{Binding Time}" 
         DependentValueBinding="{Binding Value}" 
       > 
      <chartingToolkit:LineSeries.DependentRangeAxis> 
       <chartingToolkit:LinearAxis 
           Orientation="Y" 
           Title="Y Value" 
           ShowGridLines="True" 
         Maximum=".009" 
         Minimum=".001"/> 
      </chartingToolkit:LineSeries.DependentRangeAxis> 
     </chartingToolkit:LineSeries> 

     <chartingToolkit:Chart.Axes> 
      <chartingToolkit:LinearAxis Orientation="X" 
             Title="X Value" 
             ShowGridLines="True" 
             /> 
     </chartingToolkit:Chart.Axes> 
    </chartingToolkit:Chart> 
</Grid> 

Y el código subyacente:

using System.Collections.Generic; 
    using System.Windows; 

namespace WpfChartApplication 
{ 
public partial class MainWindow : Window 
{ 


    public MainWindow() 
    { 
     InitializeComponent(); 

     var cVm = new ChartViewModel(); 
     chart1.DataContext = cVm; 
    } 
} 

public class ChartViewModel 
{ 
    public List<Rate> Rates { get; set; } 

    public ChartViewModel() 
    { 
     Rates = new List<Rate>(); 

     Rates.Add(new Rate(1, .001)); 
     Rates.Add(new Rate(2, .003)); 
     Rates.Add(new Rate(3, .001)); 
     Rates.Add(new Rate(4, .002)); 
     Rates.Add(new Rate(5, .001)); 
     Rates.Add(new Rate(6, .001)); 
     Rates.Add(new Rate(7, .003)); 
     Rates.Add(new Rate(8, .007)); 
     Rates.Add(new Rate(9, .009)); 
     Rates.Add(new Rate(10, .008)); 
    } 
} 

public class Rate 
{ 
    public Rate(int time, double value) 
    { 
     Time = time; 
     Value = value; 
    } 

    public int Time { get; set; } 
    public double Value { get; set; } 
} 
} 

Respuesta

6

puede cambiar el estilo de etiqueta para obtener el efecto

<Style x:Key="NumericAxisLabelStyle" TargetType="{x:Type chartingToolkit:NumericAxisLabel}"> 
    <Setter Property="IsTabStop" Value="False" /> 
    <Setter Property="StringFormat" Value="{}{0:0.###}" /> 
    <Setter Property="Template"> 
    <Setter.Value> 
     <ControlTemplate TargetType="{x:Type chartingToolkit:NumericAxisLabel}"> 

     <TextBlock Text="{TemplateBinding FormattedContent}" /> 
     </ControlTemplate> 
    </Setter.Value> 
    </Setter> 
</Style> 

<chartingToolkit:Chart Name="chart1"> 
    <chartingToolkit:LineSeries Title="Rates" 
           ItemsSource="{Binding Rates}" 
           IndependentValueBinding="{Binding Time}" 
           DependentValueBinding="{Binding Value}"> 
    <chartingToolkit:LineSeries.DependentRangeAxis> 
     <chartingToolkit:LinearAxis Orientation="Y" 
            Title="Y Value" 
            ShowGridLines="True" 
            AxisLabelStyle="{StaticResource NumericAxisLabelStyle}" 
            Maximum=".009" 
            Minimum=".001" /> 
    </chartingToolkit:LineSeries.DependentRangeAxis> 
    </chartingToolkit:LineSeries> 
    <chartingToolkit:Chart.Axes> 
    <chartingToolkit:LinearAxis Orientation="X" Title="X Value" ShowGridLines="True" /> 
    </chartingToolkit:Chart.Axes> 
</chartingToolkit:Chart> 

espero que esto ayude. ..

+0

Me sorprende que este no sea el comportamiento predeterminado para el control de gráfico. ¡Gracias por tu ayuda! –

+0

@senor_cardgage no hay problema :-) – punker76

Cuestiones relacionadas