1
votes

Im trying to create a chart the has a base 10 logarithmic scale for the x axis with a range from 1 to 1000. I seem to be able create the axis during design time but whenever the form is loaded I get an error message saying "Chart Area Axes - A logarithmic scale cannot be used for this axis.

Is this a limitation on the MSChart control? why am I not able to create a log scale on the X Axis?

4
Any code? Stack trace? Is it a typo in exception message? Can't you just copy/paste it?default locale
Chart Area Axes - A logarithmic scale cannot be used for this axis. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: Chart Area Axes - A logarithmic scale cannot be used for this axis.trip
We could not understand what's the problem with your code unless you post relevant parts of it. And, again, paste stack trace.default locale
I'm not able to paste the stack trace. Its too long.trip
if you could just copy and paste say the first 50 lines of the stack trace, even that may be helpfulkolin

4 Answers

3
votes

It is because for a logarithm scale, the values must be greater than zero. Charting.CHart treats empty chart as being consisting of zeros (I know it is weird). This error can be very difficulty to debug. Therefore, it mean that the graph cannot be EMPTY if any of the axis is a logarithm scale. What I normally do is set the axis as linear and the change it immediately after plot on the graph (and checking no zeros or negative values on the logarithm scale). Also, remember to change the axis to linear before clearing the axis and plotting. Hope this helps someone.

3
votes

I propose to use SuppressExceptions property which allows to ignore some exceptions, also that one connected with zeros in axis with logarithmic scale. I think this is the best solution for that situation instead manipulating data.

chart.SuppressExceptions = true;
2
votes

It's not just about zeroes but also about having your values in the right datatype. Suppose you're populating the chart with values form a DataTable. If you haven't specified the type, .NET will automatically assume they are strings and thus not be able to plot a logarithmic scale.

incomplete specification of the datatable:

        PP = New DataTable
        PP.Columns.Add("X-value")
        PP.Columns.Add("Y-value")

complete specification:

        PP = New DataTable
        PP.Columns.Add("X-value", Type.GetType("System.Double"))
        PP.Columns.Add("Y-value", Type.GetType("System.Double"))

In the first example the exception will be thrown. In the second it won't.

0
votes

Not all chart types support logarithmic scales; try changing the chart type e.g. to Line Chart.

Chart types: http://msdn.microsoft.com/en-us/library/dd489233.aspx

ChartType property: http://msdn.microsoft.com/en-us/library/system.windows.forms.datavisualization.charting.series.charttype.aspx