Vertical axis ticks overlap the labels when adding a line graph

Nov 8, 2011 at 8:06 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)
            foreach (var item in removeList)
            List<DateTime> dt = new List<DateTime>();
            List<int> values = new List<int>();
            for (int i = 0; i < 100; 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);
                     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();




<Window x:Class="DynamicDataDisplayChart.MainWindow"
        Title="MainWindow" Height="350" Width="525">
        <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:HorizontalDateTimeAxis Name="xAxis"/>
                <d3:VerticalIntegerAxis Name="yAxis"/>

Thanks in advance...


Jul 27, 2012 at 2:26 PM

This is very late but better to leave it as reference, maybe some other runs into the same issue. I was running into the same overlapping problem in the vertical axis. The problem was due to removing children of type LineGraph from the plotter. Then after a while opted for doing the following and works fine:

                //Only replace the line segments
                if (_plotter.Children.OfType().Count() > lineIndex) {
                    var lineGraph = _plotter.Children.OfType().ElementAt(lineIndex);
                    lineGraph.DataSource = values; 
                    lineGraph.Stroke = rail.Brush; 
                    lineGraph.Description = new PenDescription(rail.Name);
                } else //Or add a new one 
                    _plotter.AddLineGraph(values, rail.Color, StrokeThickness, rail.Name);

So as you see, the idea is to check if a lineGraph already exists in certain position of the children collection of the plotter and update its values. Hope this will help someone else.