Как изменить X-ось ChartingToolkit LineChart - PullRequest
0 голосов
/ 03 января 2019

У меня проблемы с форматированием оси x моего графика соответственно. Ось x показывает значения типа DateTime. Я хотел бы контролировать, какая информация отображается на оси х. Например, только секунды и миллисекунды. Кроме того, я хотел бы установить интервал для оси x, если слишком много значений для отображения.

Вот мое текущее состояние:

Я использую chartingToolkit со следующей ссылкой для отображения LineChart с двумя строками:

xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" 

Ввод данных для графика выглядит следующим образом:

public ObservableCollection<List<KeyValuePair<DateTime,int>>> ListOutputGraph { get; set; }

Эта наблюдаемая коллекция содержит список для каждой из отображаемых строк

Теперь я строю график через XAML так:

                <chartingToolkit:Chart Name="LineChart1" BorderThickness="0" VerticalAlignment="Top" Margin="0,-30,0,0" Height="382">

                    <!-- Line P -->
                    <chartingToolkit:LineSeries Name="P" Title="P Out" DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding [0]}" IsSelectionEnabled="True" >
                        <chartingToolkit:LineSeries.DataPointStyle>
                            <Style TargetType="chartingToolkit:DataPoint">
                                <Setter Property="Background" Value="Red" />
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="chartingToolkit:LineDataPoint">
                                            <Grid x:Name="Root" Opacity="1">
                                                <ToolTipService.ToolTip>
                                                    <StackPanel Margin="2,2,2,2">
                                                        <ContentControl Content="Data Row: P" FontWeight="Bold" />
                                                        <ContentControl Content="{TemplateBinding IndependentValue}"  ContentStringFormat="Time:     {0}" />
                                                        <ContentControl Content="{TemplateBinding DependentValue}" ContentStringFormat="Value:    {0}"/>
                                                    </StackPanel>
                                                </ToolTipService.ToolTip>
                                                <Ellipse StrokeThickness="{TemplateBinding BorderThickness}" Stroke="{TemplateBinding BorderBrush}" Fill="{TemplateBinding Background}"/>
                                            </Grid>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </chartingToolkit:LineSeries.DataPointStyle>
                    </chartingToolkit:LineSeries>

                    <!-- Line L -->
                    <chartingToolkit:LineSeries Name="L" Title="L Out"  DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding [1]}" IsSelectionEnabled="True" >
                        <chartingToolkit:LineSeries.DataPointStyle>
                            <Style TargetType="chartingToolkit:DataPoint">
                                <Setter Property="Background" Value="Blue" />
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="chartingToolkit:LineDataPoint">
                                            <Grid x:Name="Root" Opacity="1">
                                                <ToolTipService.ToolTip>
                                                    <StackPanel Margin="2,2,2,2">
                                                        <ContentControl Content="Data Row: L" FontWeight="Bold" />
                                                        <ContentControl Content="{TemplateBinding IndependentValue}"  ContentStringFormat="Time:      {0}" />
                                                        <ContentControl Content="{TemplateBinding DependentValue}" ContentStringFormat="Value:     {0}"/>
                                                    </StackPanel>
                                                </ToolTipService.ToolTip>
                                                <Ellipse StrokeThickness="{TemplateBinding BorderThickness}" Stroke="{TemplateBinding BorderBrush}" Fill="{TemplateBinding Background}"/>
                                            </Grid>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </chartingToolkit:LineSeries.DataPointStyle>
                    </chartingToolkit:LineSeries>
                </chartingToolkit:Chart>

Результат в настоящее время выглядит следующим образом:

enter image description here

...