0
votes

I am trying to create a chart that has a base 10 logarithmic scale for both the X and Y axes. I keep getting the exception below when, I assume, the chart is bound.

An exception of type 'System.InvalidOperationException' occurred in System.Web.DataVisualization.dll but was not handled in user code

Chart Area Axes - A logarithmic scale cannot be used for this axis.

StackTrace: at System.Web.UI.DataVisualization.Charting.ChartArea.SetDefaultFromIndexesOrData(Axis axis, AxisType axisType) at System.Web.UI.DataVisualization.Charting.ChartArea.SetDefaultAxesValues() at System.Web.UI.DataVisualization.Charting.ChartArea.SetData(Boolean initializeAxes, Boolean checkIndexedAligned) at System.Web.UI.DataVisualization.Charting.ChartArea.ReCalcInternal() at System.Web.UI.DataVisualization.Charting.ChartPicture.Paint(Graphics graph, Boolean paintTopLevelElementOnly) at System.Web.UI.DataVisualization.Charting.ChartImage.GetImage(Single resolution) at System.Web.UI.DataVisualization.Charting.Chart.SaveImage(Stream imageStream) at System.Web.UI.DataVisualization.Charting.Chart.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) at System.Web.UI.Control.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) at System.Web.UI.UpdatePanel.RenderChildren(HtmlTextWriter writer) at System.Web.UI.Control.Render(HtmlTextWriter writer) at System.Web.UI.UpdatePanel.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) at System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter writer) at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) at System.Web.UI.Control.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) at System.Web.UI.Control.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at ASP.user_controls_test_controls_individualtestcontrol_ascx.__RenderPanel_Tables(HtmlTextWriter __w, Control parameterContainer) in C: (And so on........)

Here is the code for the chart in the front-end:

<asp:Chart ID="VoltageVsCurrent" runat="server" BackColor="AliceBlue" ImageLocation="~/Images/TempImages/ChartPic_#SEQ(300,3)" Width="600px" Height="400px">
    <Series>
        <asp:Series Name="Series1" ChartType="Point" LegendText="Current (A)" />
        <asp:Series Name="Series2" ChartType="Spline" LegendText="Spline" BorderWidth="2" />
    </Series>
    <Legends>
        <asp:Legend DockedToChartArea="ChartArea1" Alignment="Center" />
    </Legends>
    <ChartAreas>
        <asp:ChartArea Name="ChartArea1">
            <AxisX Title="Voltage (Volts)" TitleFont="Segoe UI, 12pt, style=Italic">
                <MajorGrid Enabled="false" />
                <MajorTickMark Enabled="true" />
            </AxisX>
            <AxisY Title="Current (Amps)" TitleFont="Segoe UI, 12pt, style=Italic" />
        </asp:ChartArea>
    </ChartAreas>
    <Titles>
        <asp:Title Text="Current vs Voltage" Font="Segoe UI, 16pt, style=Bold, Underline" />
    </Titles>
</asp:Chart>

And the code that sets the chart in the back-end:

VoltageVsCurrent.DataSource = ChartDataSource
VoltageVsCurrent.Series("Series1").XValueMember = VoltageColumn
VoltageVsCurrent.Series("Series1").YValueMembers = CurrentColumn
VoltageVsCurrent.Series("Series2").YValueMembers = CurrentColumn
VoltageVsCurrent.ChartAreas("ChartArea1").AxisX.IsLogarithmic = True
VoltageVsCurrent.ChartAreas("ChartArea1").AxisY.IsLogarithmic = True
VoltageVsCurrent.ChartAreas("ChartArea1").AxisX.IsStartedFromZero = False
VoltageVsCurrent.ChartAreas("ChartArea1").AxisY.IsStartedFromZero = False
VoltageVsCurrent.Series("Series1").IsXValueIndexed = False
VoltageVsCurrent.Series("Series2").IsXValueIndexed = False
VoltageVsCurrent.SuppressExceptions = True
VoltageVsCurrent.DataBind()

I added the IsStartedFromZero = False, IsXValueIndexed = False, and SuppressExceptions = True because of suggestions I found elsewhere while researching this problem. None of them seem to have helped.

I have checked that before the DataBind() the ChartDataSource had actual values in it, none of which were zero or negative. An example of the ChartDataSource. (I know it's not logarithmic data, but it should still plot)

Any help is much appreciated! Thank you!

1
I'm not sure you can do what you want to do. The Chart Area Axes - A logarithmic scale cannot be used for this axis leads me to believe you may need a different control. What that control is, I have no idea.Lews Therin
Then why would it be an existing property of the AxisX and AxisY which are the only relevant options for the chartAreawedsa5
This question is pretty similar. Do any answers there help?Lews Therin

1 Answers

0
votes

One thing to watch out for is that one cannot take a logarithm of 0 (much like one cannot divide by zero). Therefore, if you have any points in your data that have an X or Y value of zero or less you will be unable to use logarithmic scaling.

Maybe try excluding any points where X <= 0 or Y <= 0.