Axes behave strangely when refreshing the data

Nov 13, 2009 at 2:12 PM

Hi,

I've got a very simple WPF app with a ChartPlotter containing two line graphs (one shown with blue points, the other with red).  The strange thing is when I refresh the data (just by removing the lines and adding them again)...

theGraph.RemoveUserElements();
theGraph.AddLineGraph(viewModel.BluePoints.AsDataSource(), null, new PointMarker(Brushes.Blue), null);
theGraph.AddLineGraph(viewModel.RedPoints.AsDataSource(), null, new PointMarker(Brushes.Red), null);

...then the axes seem to behave strangely.

The points start off in their correct positions (i.e., {0,0}, {1,10}, {2,20}, {3,30}, {4,40}, {5,50})...

...but after refreshing the data with the code above, the points seem to stay in the right place but the axes show the wrong values...

The axes will correct themselves if you resize the window.  Any idea what might be causing this or if there's a way to stop it?

(There's a zip of the sample app here if it helps.)

Best regards,
IanR

Editor
Nov 13, 2009 at 5:37 PM

Hi IanR,

thank you for discovering this bug. It will be fixed in next version of D3.

If you are using D3 from source code, you can open file DynamicDataDisplau/Charts/Axes/AxisBase.cs, find string 'if (viewportPropertyChangedEnters > 2)' and change 2 to 4. This should help.

Best regards,

Mikhail.

Dec 16, 2009 at 4:03 PM

Hi Mikhail,

The latest code (31108) does fix the problem with the axes going wrong...but the axes seem to wobble about a bit when the data is refreshed.  Do you know what might be causing this, or if there's a way to prevent it?

Best regards,
IanR

 

Editor
Dec 17, 2009 at 1:12 PM

Hi IanR,

can you please give some repro for this 'wobbling'?

Mikhail.

Dec 21, 2009 at 2:56 PM

Yeah - there's a sample here that reproduces it.

Pressing the 'Refresh Display' button removes the line graphs and adds them again.  The graph seems to redraw slightly differently each time the button is pressed which causes the 'wobbling' effect.

Thanks for looking into this.  Let me know if you need anything else.

Thanks,
IanR

Editor
Dec 26, 2009 at 4:39 PM

Hi IanR,

currently i'm not capable to fix this problem, thought I have found its reason. I'll notify you if I find some solution.

Best regards and happy holidays,

Mikhail.

Jul 12, 2012 at 4:00 AM

Mikhail,

I know it has been several years since your last post, but if you're still following this thread, it would be great to have an update on what you thought was the root cause of the issue. I'd be more than willing to try fixing it, if possible.

Thanks,

Evan

 

thecentury wrote:

Hi IanR,

currently i'm not capable to fix this problem, thought I have found its reason. I'll notify you if I find some solution.

Best regards and happy holidays,

Mikhail.

Jul 13, 2012 at 10:34 PM

Good news! While I haven't dealt with the root cause of the issue, I did find a decent workaround that doesn't make me cringe too much.

This stemmed from a discovery I made: If you move the chart - even slightly - you can add and remove data as much as you want and the chart will no longer have the graphical "wobble" along the x-axis anymore. I found that you can instead move the graph programmatically just a tiny amount, and the glitch will no longer be present.

Here's how I solved the problem:

After your chart has loaded, call the following FixChartGraphicalGlitch() method. This method moves the chart a tiny amount to the right - it isn't even visible - which fixes the glitch.

private void FixChartGraphicalGlitch()
{
    Rect visible = Chart_Helium.Viewport.Visible;
    double width = visible.Width;
    double height = visible.Height;

    visible.Offset(-0.00001 * width, 0);

    Chart_Helium.Viewport.Visible = visible;
}	
An important item to note is that, sometimes, if you interact with the chart too quickly after it has been filled with data, it can cause additional graphical problems. To deal with this, I simply use a System.Windows.Threading.DispatcherTimer with a 500 millisecond delay to fire the FixChartGraphicalGlitch() method after I've updated the chart.

Aug 29, 2012 at 1:07 PM

Hello evan_w,

I had a problem with the Y-Axis. When auto-fit was activated the axis was wobbling.

I solved the problem by editing Viewport2D.cs method UpdateVisible(), uncommenting all lines.

Perhaps this solves your problem as well.