Solved

asp.net chart control how to create to y axis

Posted on 2015-01-21
2
576 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SlingPlayer alternatives 1 35
ADO.NET ENTITY DATA MODEL 3 32
Error on Add method 1 38
how to read json value 2 31
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now