I have a few problems trying to tame the x axis of my mschart.
I use the chart to plot multiple histograms simultaneously, and as you can see my x scale is a mess (see image below). My main question here is: how can I make it look as clean as the y axis. What I mean by "clean" is:
- Make the "zero value" appear in the scale.
- Put values that make sense for human readability, I mean, not in a format such as {0.000000000000}.
All the solutions I was able to find were some sort of DIY approach that doesn't work in all the variety of use cases that I am considering (or better: I am not able to make it work). My intuition says: "mschart is able to do it perfectly in the case of the Y axis. It must be also able to do it for the X axis!".
Edit: Sorry, I don't have enough reputation to post images. Here it is the graph in a imgur link =>
https://i.stack.imgur.com/iNjhg.png
On a side note, and given that as you can see in the graph almost all my values are concentrated around x=0, I wonder if there is any possibility to create a logarithmic scale for x... although I am quite aware that negative values are a problem, and 0 should be -Infinite.
Of course I could choose a better scale, but what I am trying to accomplish here is to create plenty of graphs automatically and not worry about them one by one. My solution was to cut a certain % of energy from the top and the bottom of the x axis (something like "start at min_x, go up, and once you have reached the 10% of the energy as a sum, this will be the new min_x. Same thing from max_x downwards."), but this solution still leaves a narrow spike around zero. I could go with higher values of cut energy, but I am afraid it wouldn't work in all cases...
Any hints? Thank you very much.
Edit2: this is an example of the type of series of this graph. As it is an histogram computed for N bins between x_min and x_max, the values of X are quite a mess.
-67.7591400146485,0
-66.0651615142823,0
-64.3711830139161,0
-62.6772045135498,0
-60.9832260131836,0
-59.2892475128174,0
-57.5952690124512,0
-55.901290512085,0
-54.2073120117188,0
-52.5133335113526,0
-50.8193550109863,0
-49.1253765106201,0
-47.4313980102539,0
-45.7374195098877,0
-44.0434410095215,0
-42.3494625091553,0
-40.6554840087891,0
-38.9615055084228,0
-37.2675270080566,0
-35.5735485076904,0
-33.8795700073242,0
-32.185591506958,0
-30.4916130065918,0
-28.7976345062256,0.000405350628293474
-27.1036560058594,0
-25.4096775054932,0
-23.7156990051269,0
-22.0217205047607,0.000405350628293474
-20.3277420043945,0.000810701256586948
-18.6337635040283,0.000810701256586948
-16.9397850036621,0.000810701256586948
-15.2458065032959,0.0016214025131739
-13.5518280029297,0.00121605188488042
-11.8578495025635,0.00283745439805432
-10.1638710021973,0.00364815565464126
-8.46989250183105,0.00405350628293474
-6.77591400146484,0.0105391163356303
-5.08193550109863,0.0121605188488042
-3.38795700073241,0.0186461289014998
-1.6939785003662,0.0283745439805432
7.54951656745106E-15,0.835022294284556
1.69397850036622,0.0413457640859343
3.38795700073243,0.0206728820429672
5.08193550109864,0.00608025942440211
6.77591400146485,0.00486420753952169
8.46989250183106,0.000810701256586948
10.1638710021973,0.000810701256586948
11.8578495025635,0.000405350628293474
13.5518280029297,0.00243210376976084
15.2458065032959,0.000810701256586948
16.9397850036621,0.000405350628293474
18.6337635040283,0
20.3277420043945,0
22.0217205047607,0
23.715699005127,0
25.4096775054932,0
27.1036560058594,0
28.7976345062256,0
30.4916130065918,0
32.185591506958,0
Edit3: so I found a solution that mixes this post and this other post.
Dim bestGuessInterval As Double = (maxGraphValue - minGraphValue) / numberOfPointsInGraph
newChartArea.AxisX.Interval = RoundToClosest(bestGuessInterval)
'It uses the custom function "RoundToClosest":
Private Function RoundToClosest(ByVal value As Double) As Double
Dim digits As Integer = NumberOfZerosAfterDecimalPoint(value)
Return Math.Round(value, digits)
End Function
Private Function NumberOfZerosAfterDecimalPoint(ByVal value As Double) As Integer
Dim numberAsString As String = value.ToString()
Dim charCounter As Integer = 0
Dim digitsAfterPoint As Boolean = False
For Each character As String In numberAsString
If character = "." Then
digitsAfterPoint = True
charCounter += 1
Else
If CDbl(character) <> 0 Then
Return charCounter
Else
If digitsAfterPoint Then
charCounter += 1
End If
End If
End If
Next
End Function