0
votes

I have been trying to solve this issue from some time now. The symptom is with the X axis I see that the value get overrided to a lower value from what I have set it at in Chart1.ChartAreas(0).AxisX.Minimum = Xmin (8.5 in this case) . However when I times the values by 100 the curve seems to center to a min and max. I am also not experiencing this with the Y axis at all. In the picture attached I am setting the min to 8.5 ( as seen where the curve starts in the picture. I also notice if I set the min below 8 it will let me set it to that. So this leads me to believe there is some sort of value that its overriding ratio to make the minimum inside of MSchart.

Imports Microsoft.VisualBasic

Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.IO



Imports System.Drawing






Public Class Test
    Inherits System.Web.UI.Page



    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load


        Dim value As Double
        Dim xxmax As Double
        Dim yymax As Double
        Dim xxmin As Double
        Dim yymin As Double
        Dim XPlot As New ArrayList
        Dim YPlot As New ArrayList


        XPlot.Add(10.1)
        XPlot.Add(10.15)
        XPlot.Add(10.2)
        XPlot.Add(10.25)
        XPlot.Add(10.3)

        YPlot.Add(1)
        YPlot.Add(2)
        YPlot.Add(3)
        YPlot.Add(4)
        YPlot.Add(5)




        xxmin = 10.1
        xxmax = 10.3
        yymin = 1
        yymax = 5




        Chart1.Series.Clear()
        Chart1.Series.Add("Polfit Fit")
        Chart1.Series("Polfit Fit").XValueType = System.Web.UI.DataVisualization.Charting.ChartValueType.Int32
        Chart1.Series("Polfit Fit").ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line

        Chart1.Series.Add("Plotted Data")
        Chart1.Series("Plotted Data").XValueType = System.Web.UI.DataVisualization.Charting.ChartValueType.Int32
        Chart1.Series("Plotted Data").ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Point
        Chart1.Series("Plotted Data").MarkerStyle = System.Web.UI.DataVisualization.Charting.MarkerStyle.Circle
        Chart1.Series("Plotted Data").MarkerSize = 10
        Chart1.Series("Plotted Data").MarkerColor = Color.Green
        Chart1.Series("Polfit Fit").Color = Color.Blue
        Dim mylegend As New System.Web.UI.DataVisualization.Charting.Legend
        mylegend.Font = New System.Drawing.Font("Arial", 12, System.Drawing.FontStyle.Bold)
        mylegend.Name = "Legend"
        mylegend.BorderWidth = 4
        mylegend.BorderColor = Color.Black
        mylegend.Docking = DataVisualization.Charting.Docking.Right
        Chart1.Legends.Add(mylegend)
        Chart1.ChartAreas(0).AxisX.Title = Value
        Chart1.ChartAreas(0).AxisX.TitleFont = New System.Drawing.Font("Arial", 12, System.Drawing.FontStyle.Bold)
        Chart1.ChartAreas(0).AxisY.TitleFont = New System.Drawing.Font("Arial", 12, System.Drawing.FontStyle.Bold)
        Chart1.ChartAreas(0).AxisY.Title = "Margin Of Safety"
        Chart1.ChartAreas(0).AxisX.IsMarginVisible = True
        Chart1.ChartAreas(0).AxisY.IsMarginVisible = True

        Chart1.ChartAreas(0).AxisY.IsStartedFromZero = False
        Chart1.ChartAreas(0).AxisX.IsStartedFromZero = False

        Chart1.ChartAreas(0).AxisX.Interval = 0.05
        Chart1.ChartAreas(0).AxisY.Interval = 0.05
        Chart1.ChartAreas(0).AxisX.Maximum = Math.Round((xxmax + Math.Abs(xxmax * 0.0)), 6)
        Chart1.ChartAreas(0).AxisX.Minimum = Math.Round((xxmin - Math.Abs(xxmax * 0.0)), 6)
        Chart1.ChartAreas(0).AxisY.Maximum = Math.Round((yymax + Math.Abs(yymax * 0.0)), 6)
        Chart1.ChartAreas(0).AxisY.Minimum = Math.Round((yymin - Math.Abs(yymin * 0.0)), 6)
        Chart1.Height = 600
        Chart1.Width = 1500
        Dim j
        Dim b

        While j < XPlot.Count
            If Not YPlot(j) = "0" And Not (CDbl(XPlot(j)) / CDbl(YPlot(j)) = 1) Then
                Dim point As New System.Web.UI.DataVisualization.Charting.DataPoint

                point.SetValueXY((XPlot(j)), (YPlot(j)))
                Chart1.Series("Plotted Data").Points.Add(point)

            End If
            j += 1
        End While
        b = 0


    End Sub





End Class


<%@ Page Language="VB"        Inherits ="Test"    CodeFile ="Test.vb"  %>

<%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">






<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>


<form     runat="server"  > 


<asp:Chart ID="Chart1" runat="server">
    <Series>
        <asp:Series Name="Series1">
        </asp:Series>
    </Series>
    <ChartAreas>
        <asp:ChartArea Name="ChartArea1">
        </asp:ChartArea>
    </ChartAreas>
</asp:Chart>




 </form>


    </body>
</html>

enter image description here

1
How are you adding your points to your chart? Do you have a interval type set for your x axis? A lot of times this can happen when your point type doesn't match your axis type. Also check series.IsXValueIndexed = true;, if it is true you might need to set it to false. It's hard to know for sure what the problem is since you have provided no code, for all we know somewhere in your code you could be resetting the x minimum to a lower value from 8.5. - Baddack
One more thing you could check is chart1.ChartAreas[0].AxisX.IsStartedFromZero = false; - Baddack
The interval for each of the axis is the ( max - min value ) of my plotted points and curve points. Yes I am doing chart1.ChartAreas()AxisX.IsStartedFromZero = false (not that it matters because you see the min In the chart is 8 already). series("Series Title").IsXValueIndexed = False does not fix the problem either. No I am not setting it to a lower value either. I make sure to check the object manager to see that I am setting the chart x axis min to 8.5. - Don
Point is Dim point As New System.Web.UI.DataVisualization.Charting.DataPoint - Don
I can't reproduce the issue, so something must be configured incorrectly. Do you create the chart from code or did you drag it onto your form? If you dragged it on your form, delete it and add a new one. This should at least reset all the settings to default. Maybe from there you can trace it down. edit: your interval is max - min? try setting the interval to auto and see what it does. - Baddack

1 Answers

0
votes

Chart1.Series("Plotted Data").XValueType = System.Web.UI.DataVisualization.Charting.ChartValueType.Int32

should be

Chart1.Series("Plotted Data").XValueType = System.Web.UI.DataVisualization.Charting.ChartValueType.Double

That is what was causing the problem. Thank you Babback that solves the issue.