将asp.net图表轴设置为对数

时间:2015-10-14 19:37:30

标签: asp.net vb.net graph charts logarithm

我正在尝试为X轴和Y轴创建一个基数为10的对数刻度的图表。当我假设图表被绑定时,我一直得到下面的例外。

  

类型' System.InvalidOperationException'的例外情况发生在System.Web.DataVisualization.dll中但未在用户代码中处理

     

图表区域轴 - 对数刻度不能用于此轴。

     

堆栈跟踪:          在System.Web.UI.DataVisualization.Charting.ChartArea.SetDefaultFromIndexesOrData(Axis轴,AxisType axisType)          在System.Web.UI.DataVisualization.Charting.ChartArea.SetDefaultAxesValues()          在System.Web.UI.DataVisualization.Charting.ChartArea.SetData(Boolean initializeAxes,Boolean checkIndexedAligned)          在System.Web.UI.DataVisualization.Charting.ChartArea.ReCalcInternal()          在System.Web.UI.DataVisualization.Charting.ChartPicture.Paint(Graphics graph,Boolean paintTopLevelElementOnly)          在System.Web.UI.DataVisualization.Charting.ChartImage.GetImage(单分辨率)          在System.Web.UI.DataVisualization.Charting.Chart.SaveImage(Stream imageStream)          在System.Web.UI.DataVisualization.Charting.Chart.Render(HtmlTextWriter writer)          在System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer,ControlAdapter adapter)          在System.Web.UI.Control.RenderControl(HtmlTextWriter编写器,ControlAdapter适配器)          在System.Web.UI.Control.RenderControl(HtmlTextWriter writer)          在System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,ICollection children)          在System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)          在System.Web.UI.Control.Render(HtmlTextWriter编写器)          在System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer,ControlAdapter adapter)          在System.Web.UI.Control.RenderControl(HtmlTextWriter编写器,ControlAdapter适配器)          在System.Web.UI.Control.RenderControl(HtmlTextWriter writer)          在System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,ICollection children)          在System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)          在System.Web.UI.UpdatePanel.RenderChildren(HtmlTextWriter writer)          在System.Web.UI.Control.Render(HtmlTextWriter编写器)          在System.Web.UI.UpdatePanel.Render(HtmlTextWriter writer)          在System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer,ControlAdapter adapter)          在System.Web.UI.Control.RenderControl(HtmlTextWriter编写器,ControlAdapter适配器)          在System.Web.UI.Control.RenderControl(HtmlTextWriter writer)          在System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,ICollection children)          在System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)          在System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter writer)          在System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)          在System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer,ControlAdapter adapter)          在System.Web.UI.Control.RenderControl(HtmlTextWriter编写器,ControlAdapter适配器)          在System.Web.UI.Control.RenderControl(HtmlTextWriter writer)          在System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,ICollection children)          在System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)          在System.Web.UI.Control.Render(HtmlTextWriter编写器)          在System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer,ControlAdapter adapter)          在System.Web.UI.Control.RenderControl(HtmlTextWriter编写器,ControlAdapter适配器)          在System.Web.UI.Control.RenderControl(HtmlTextWriter writer)          在System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,ICollection children)          在System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)          在System.Web.UI.Control.Render(HtmlTextWriter编写器)          在System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer,ControlAdapter adapter)          在System.Web.UI.Control.RenderControl(HtmlTextWriter编写器,ControlAdapter适配器)          在System.Web.UI.Control.RenderControl(HtmlTextWriter writer)          at ASP.user_controls_test_controls_individualtestcontrol_ascx .__ RenderPanel_Tables(HtmlTextWriter __w,Control parameterContainer)在C :(等等........)

以下是前端图表的代码:

<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>

在后端设置图表的代码:

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()

我添加了IsStartedFromZero = FalseIsXValueIndexed = FalseSuppressExceptions = True,因为我在研究此问题时发现了其他地方的建议。他们似乎都没有帮助。

我已经检查过DataBind() ChartDataSource之前的实际值,其中没有一个是零或负数。 An example of the ChartDataSource.(我知道它不是对数数据,但它仍应该绘制)

非常感谢任何帮助!谢谢!

1 个答案:

答案 0 :(得分:0)

需要注意的一点是,不能将对数设为0(很像一个不能除以零)。因此,如果数据中的任何点的X或Y值为零或更小,则无法使用对数缩放。

也许尝试排除X <= 0或Y <= 0的任何点。