سؤال

I am using System.Windows.Controls.DataVisualization.Charting to create a line graph in WPF It it working ok as the data is being diplayed. However depending on the data being accessed it gets very messy and scrunched. Is there anyway to may the graph scrollable to the right if the data gets too wide?

Here is my xaml of the graph

            <DVC:Chart Canvas.Top="80" Grid.Column="1" Grid.Row="0" Canvas.Left="10" Name="mcChart" Background="LightSteelBlue" Height="676">

                <DVC:Chart.Series>
                    <DVC:LineSeries Title="File Count" IndependentValueBinding="{Binding Path=Key}"
                          DependentValueBinding="{Binding Path=Value}"  >

                    </DVC:LineSeries>

                </DVC:Chart.Series>

            </DVC:Chart>

From the CS code I am just setting the data of the graph to be a list of KeyValuePair

  ((LineSeries)mcChart.Series[0]).ItemsSource = data.ToArray(); 

here is the graph showing the obvious issue.

linegraph

Another option if I cannot scroll it is to just remove the x axis lables. That is my second choice, but i can't figure out how to do that either. Thanks

هل كانت مفيدة؟

المحلول

Remove the x axis labels 

Can do this using AxisLabelStyle of axis.

    void DrawLineChart()
    {
      var line1 = new LineSeries();
      line1.IndependentAxis = new LinearAxis(){Orientation = AxisOrientation.X,AxisLabelStyle = GetHidenAxisStyle()};
    }


    private Style GetHidenAxisStyle()
    {
        Style style = new Style(typeof(AxisLabel));
        Setter st2 = new Setter(AxisLabel.BorderBrushProperty,
                                    new SolidColorBrush(Colors.White));
        Setter st3 = new Setter(AxisLabel.BorderThicknessProperty, new Thickness(0));
        Setter st4 = new Setter(AxisLabel.TemplateProperty, null);
        style.Setters.Add(st2);
        style.Setters.Add(st3);
        style.Setters.Add(st4);
        return style;
    }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top