Vertical axis labels overridden by ticks after adding line graph

Nov 8, 2011 at 6:43 AM
Edited Nov 8, 2011 at 7:03 AM

Hi all,

Very very nice chart mechanism, simple and does the job.

I'm having a problem with the labels of the vertical axis. I am creating a line graph by removing all LineGraphs and MarkerPointGraphs from the plotter's children, then creating a line chart, and calling FitToView (to show the graph).

for some unknown reason, the ticks of the vertical axis move to the left thus hiding the labels when I call the function again, the ticks go back to their good position, again, they hide and so forth, it is not consistent, sometimes for a few times the ticks stay ok, and then they hide the label for some iterations. very frustrating since I am doing the exact same thing over and over, and getting different results.

I'm using windows 7, 64bit if it matters...

below is my code behind function to draw a line (called when I left click on the graph) and the XAML that created the chart.

code behind:

private void DrawLine()
        {
            List<IPlotterElement> removeList = new List<IPlotterElement>();
            foreach (var item in plotter.Children)
            {
                if (item is LineGraph || item is MarkerPointsGraph)
                {
                    removeList.Add(item);
                }
            }
            foreach (var item in removeList)
            {
                plotter.Children.Remove(item);
            }
           
            List<DateTime> dt = new List<DateTime>();
            List<int> values = new List<int>();
            for (int i = 0; i < 100; i++)
            {
                dt.Add(DateTime.Now.AddMinutes(i));
                values.Add(i * 2);
            }
            var datesDataSource = new EnumerableDataSource<DateTime>(dt);
            datesDataSource.SetXMapping(x => xAxis.ConvertToDouble(x));

            var valuesDataSource = new EnumerableDataSource<int>(values);
            valuesDataSource.SetYMapping(y => y);

            CompositeDataSource compositeDataSource = new CompositeDataSource(datesDataSource, valuesDataSource);
           
            plotter.AddLineGraph(compositeDataSource,
                     new Pen(Brushes.Green, 2),
                     new CirclePointMarker { Size = 6.0, Pen = new Pen(Brushes.Black, 1.0), Fill = Brushes.LightGreen},
                     new PenDescription("Data"));

            header.Content = DateTime.Now.ToShortTimeString();
            yAxisTitle.Content = DateTime.Now.ToShortTimeString();
            xAxisTitle.Content = DateTime.Now.ToShortTimeString();

            plotter.Viewport.FitToView();
        }

 

XAML:

<Window x:Class="DynamicDataDisplayChart.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <d3:ChartPlotter Name="plotter" Margin="10,10,20,10">
            <d3:Header Name="header" FontFamily="Arial" Content="Bug Information"/>
            <d3:VerticalAxisTitle Name="yAxisTitle" FontFamily="Arial"/>
            <d3:HorizontalAxisTitle Name="xAxisTitle" FontFamily="Arial"/>
            <d3:ChartPlotter.HorizontalAxis>
                <d3:HorizontalDateTimeAxis Name="xAxis"/>
            </d3:ChartPlotter.HorizontalAxis>
            <d3:ChartPlotter.VerticalAxis>
                <d3:VerticalIntegerAxis Name="yAxis"/>
            </d3:ChartPlotter.VerticalAxis>
        </d3:ChartPlotter>       
    </Grid>
</Window>

Thanks in advance...

Etai