Problems with a square scatter chart

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
ewan
Posts: 3
Joined: Fri May 26, 2017 9:02 am

Problems with a square scatter chart

Post by ewan » Wed Sep 25, 2019 3:01 pm

Our software requires a scatter chart with a perfectly square charting area, with the same values in each axis, and a circular shaded region.

To do this I'm using a FreeformPoint series, forcing the chart's width to equal the chart's height, and setting the ViewXY's ManualAspectRatioWH to 1. To create the shaded region I'm using a SeriesPoint at 0,0 and setting the PointShapeStyle to a circle of the desired size and thickness. To get the correct size for this circle I'm using a coefficient value (charting area height divided by axis range). This gives me almost perfect results, but there are problems.
Chart.png
Chart.png (36.94 KiB) Viewed 5893 times
You can see in the screenshot that the shaded area appears to be off centre, with more white space showing on the x axis before -150 than after 150. There is a similar problem in the y axis.

After literally pixel counting I found that the gridlines are uneven. Two "rows" are an extra pixel in height, and one column is an extra pixel in width (I've marked the problematic rows and columns with red lines in the picture). The chart is also two pixels wider than it is taller. This is causes the shaded area to be the incorrect size and thickness.

Accuracy is crucial for our software, so I have to ensure that all chart elements are drawn in the correct places to the correct size.

Is it possible to create a perfectly square charting area without these inconsistencies?

Also do you know of a better way to achieve the circular shaded area in Lightning Chart? The size and thickness of the area must be tied to the axes, so they will resize on zooming. The current coefficient method was the only possible way in a previous charting package so it's been carried over for now. I understand this is a rather non-standard chart, but I appreciate your help.

We are currently using v.8.3.1_20180404

Thanks in advance, and let me know if you need any additional information.

Ewan.

Arction_LasseP
Posts: 141
Joined: Wed Mar 27, 2019 1:05 pm

Re: Problems with a square scatter chart

Post by Arction_LasseP » Thu Sep 26, 2019 11:33 am

Hello Ewan,

This issue is most likely caused when LightningChart cannot divide the available graph size in pixels equally. The chart has a certain size in pixels, as does the graph area (the area limited by margins, where data is shown). You can actually check the exact sizes of these by calling _chart.ActualWidth and _chart.ViewXY.XAxes[0].GetActiveAxisArea().Width. Note that these work only after the chart has been rendered.

If your graph area has height of for example 700 and you try to divide that in 12 segments separated by grid lines (which are also one pixel wide, 13 in total as one on top and one on bottom), you will have this kind of issue. The segments end up having height of 57,25 pixels. As partial pixels cannot be rendered, the chart ends up having segment sizes like 57, 57, 57, 58, 57...

To fix this you could try to modify the chart size and the graph area size, the latter can be done by changing the margin settings.

_chart.Width = 700;
_chart.Height = 700;
_chart.ViewXY.AxisLayout.AutoAdjustMargins = false;
_chart.ViewXY.Margins = new Thickness(40, 20, 10, 40);

The AspectRatio is usually the best option in these kind of cases. You could also double-check that it is set correctly. We have a couple of demo examples which use that: "Intensity mesh, circle/polar geometry", "Image Viewer" and "Silicon wafer map analysis" on WinForms side.

How the circular area is created probably will not have any effect on the issue itself, but you can also create it with an Annotation or an EventMarker (Chart- or SeriesEventMarker). The markers have the benefit of having Offset-property which could be used to adjust their position in pixels.

There is always an option to send our technical support at support(at)arction.com a sample application, and we can take a look at the issue (though you need to have a valid subscription for more technical support).

Best regards,
Lasse

ewan
Posts: 3
Joined: Fri May 26, 2017 9:02 am

Re: Problems with a square scatter chart

Post by ewan » Fri Sep 27, 2019 9:47 am

If I understand correctly, you're saying that rather than the gridlines being overlaid onto the chart, they actually add to the height and width? So a chart with 12 segments and gridlines, would be 13 pixels taller than the same chart without gridlines?

If that's the case then it would certainly explain the issues I've been seeing with the shaded area.

Is there a way to overlay the gridlines rather than "insert" them into the height and width?

I'm currently calculating the height of the chart area using a formula I found in another post:

_chart.ActualHeight - (_chart.ViewXY.Margins.Top + _chart.ViewXY.Margins.Bottom)

Will this give the correct size?

I've tried using the variables you suggested, and while _chart.ViewXY.XAxes[0].GetActiveAxisArea().Width and Height works fine, _chart.ViewXY.YAxes[0].GetActiveAxisArea().Width and Height always returns zero.

Arction_LasseP
Posts: 141
Joined: Wed Mar 27, 2019 1:05 pm

Re: Problems with a square scatter chart

Post by Arction_LasseP » Fri Sep 27, 2019 11:50 am

Hello Ewan,

I double-checked our source code. I might have given a bit of misinformation here, apologies for that. The gridlines are actually overlaying. The issue is still the same though; the graph area cannot be equally divided between the segments, and due to rounding some of the segments are one pixel larger than the others.

The calculation you are using is correct but does not take into account the border that is drawn around the graph. Currently it is drawn outside graph on top and the bottom but not on left and right (we probably need to fix this in a future release to be the same on all sides). The outcome is that GetActiveAxisArea returns height value that is 2px less compared to the formula you used. Therefore GetActiveAxisArea could be more reliable.

GetActiveAxisArea should work for both axes but only if the chart has been rendered first. To ensure this you can call the methods inside AfterRendering -event.

According to our database your subscription has expired. In order to get more technical support as well as new features and bug fixes, please consider renewing the subscription.

Best regards,
Lasse

Post Reply