Solved

asp.net chart control how to create to y axis

Posted on 2015-01-21
2
592 Views
Last Modified: 2015-01-26
I have  a chart control that shows like this which is rents for a particular period.  See Image 1,  What I need to do is add another series, this on being occupancy and this follows the numbers that I would like to see on the right.  This range is from 75% to 100%, So on the right I would like to the pct's on the right the chart with another line in chart area following those pcts.

Sample html code would be great

thanks
existing chart

Open in new window

0
Comment
Question by:mgmhicks
2 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 40565730
Try something like this:
        <asp:XmlDataSource ID="XmlDataSource1" runat="server">
            <Data>
                <root>
                    <record id="1" name="Peter" amount="310000" perc="80" />
                    <record id="2" name="Paul" amount="318000" perc="95" />
                    <record id="3" name="Mary" amount="340000" perc="85" />
                </root>
            </Data>
        </asp:XmlDataSource>
        <asp:Chart ID="Chart1" runat="server" DataSourceID="XmlDataSource1" ImageStorageMode="UseImageLocation" Width="1100" Height="450">
            <Series>
                <asp:Series Name="Series1" ChartType="Line" LegendText="Net Rents" XValueMember="name" YValueMembers="amount">
                </asp:Series>
                <asp:Series Name="Series2" ChartType="Line" LegendText="Occupancy %" XValueMember="name" YValueMembers="perc" YAxisType="Secondary">
                </asp:Series>
            </Series>
            <ChartAreas>
                <asp:ChartArea Name="ChartArea1">
                    <AxisY Interval="10000" Minimum="300000" Maximum="350000">
                        <MajorGrid LineColor="Gray" />
                    </AxisY>
                    <AxisY2 Interval="5" Minimum="75" Maximum="100">
                        <MajorGrid LineColor="Silver" />
                        <LabelStyle ForeColor="Orange" />
                    </AxisY2>
                </asp:ChartArea>
            </ChartAreas>
            <Legends>
                <asp:Legend LegendStyle="Row" Docking="Top"></asp:Legend>
            </Legends>
        </asp:Chart>

Open in new window


So key parts are: YAxisType="Secondary" in the second Series and <AxisY2 Interval="5" Minimum="75" Maximum="100"> in the ChartArea.

Note that I 'manually' made sure both y axes have the same number of lines otherwise it can get ugly, but you can also play with color (as shown in the code) or disable one of them.

example pic
0
 

Author Closing Comment

by:mgmhicks
ID: 40570521
Awesome example thank you!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question