Halcyon
Halcyon

Reputation: 14971

How To Display Specific Range For Y Values Using ASP.NET Charts (MS Charts)

I'm using ASP.NET charts for the first time and am having great success. The one thing I'm wanting to do is zoom in on my chart so that the y values don't go from 0-100. For example, Say I have some point values ranging from 72 to 89. What I'd like to do is have the lowest y value be 72 and the highest y value be 89 on the y axis (it's currently displaying 0 as the lowest and 100 as the highest). Here's the code I'm using:

<asp:Chart ID="Chart1" ImageLocation="~/content/images/temp/charts/ChartPic_#SEQ(300,3)" Height="325px" Width="900px" runat="server">
    <Titles>
        <asp:Title Text="Overview" Font="Arial, 12pt, style=Bold" />
    </Titles>
    <Legends>
        <asp:Legend Font="Segoe UI, 8pt" Alignment="Center" BorderWidth="1" BorderDashStyle="Solid" BorderColor="#C6C6C6" Docking="Bottom" />
    </Legends>
    <ChartAreas>
        <asp:ChartArea Name="ChartArea1">
            <AxisY LineColor="#C6C6C6" IsInterlaced="true" InterlacedColor="#F0F0F0">
                <LabelStyle Font="Segoe UI, 8pt" ForeColor="#787878" />
                <MajorGrid LineColor="#C6C6C6" />
            </AxisY>
            <AxisX LineColor="#C6C6C6">
                <LabelStyle Font="Segoe UI, 8pt" ForeColor="#787878" />
                <MajorGrid LineColor="#C6C6C6" />
            </AxisX>
        </asp:ChartArea>
    </ChartAreas>
</asp:Chart>

protected void Page_Load(object sender, EventArgs e)
{
    var series = new Series("Overview")
    {
        Name = "Series1",
        ChartType = SeriesChartType.Line,
        MarkerStyle = MarkerStyle.Circle,
        MarkerSize = 7,
        XValueType = ChartValueType.Date,
        YValueType = ChartValueType.Double,                     
    };

    foreach (var survey in Surveys)
    {
        series.Points.AddXY(String.Format("{0:MMM yyyy}", survey.Month), survey.Score);
    }

    Chart1.Series.Add(series);
}

Upvotes: 3

Views: 5044

Answers (2)

GenericJam
GenericJam

Reputation: 3015

I'm trying to use this in combination with AJAX and the normal method kept crashing the page:

ChartArea.AxisY.Minimum = 100;
ChartArea.AxisY.Maximum = 100;

I was able to get it using this instead:

AxisScaleView yAxisScaleView = new AxisScaleView();
yAxisScaleView.Size = 100;
ChartArea.AxisY.ScaleView = yAxisScaleView;

Upvotes: 0

Josh Darnell
Josh Darnell

Reputation: 11433

You need to change the Minimum and Maximum properties of the AxisY property of your ChartArea.

So, in your Page_Load code (or wherever you need / prefer it), you could do something like this:

ChartArea1.AxisY.Minimum = 72;
ChartArea1.AxisY.Maximum = 89;

You can set some other cool things (like set the Interval) from that AxisY / AxisX property.

Upvotes: 6

Related Questions