如何使用asp.net图表工具包在“点图表”上覆盖“折线图”?

时间:2010-08-23 06:16:13

标签: c# line asp.net-charts

我目前使用asp.net图表工具包有一个点图,但是想在同一个图表上放置一条最合适的线。假设我知道如何计算线的方程(y = mx + b),我将如何在同一个图中叠加它?

2 个答案:

答案 0 :(得分:0)

需要在ChartArea中创建不同的系列并设置ChartType =“Line”

答案 1 :(得分:0)

我希望这段代码对您有帮助:

<asp:Chart ID="Chart1" runat="server" Width="1000" BorderlineColor="Black" DataSourceID="SqlDataSource1">                    
                       <series>
                <asp:Series Name="Achieved %" XValueMember="date" YValueMembers="actual_value" Color="Plum" IsValueShownAsLabel="true" Palette="Pastel" ShadowColor="Bisque" > </asp:Series>             
             <asp:Series BorderWidth="2" Name="Target" ChartType="Line" Color="#00ff00" YValueMembers="target_value" BorderDashStyle="Dash"></asp:Series>
             <asp:Series BorderWidth="2" Name="Average %" ChartType="Line" Color="Brown" YValueMembers="average" BorderDashStyle="Dash"></asp:Series>
            </series>
         <Legends>
            <asp:Legend Name="DefaultLegend" Enabled="True" Docking="Bottom" />
         </Legends>
                     <chartareas>
                        <asp:ChartArea Name="ChartArea1">
                             <axisy Title="Achieved %">
                              <MajorGrid Enabled ="False" />
                    </axisy>
                    <axisy2 Title="Objective">
                                    <MajorGrid Enabled ="False" />
                    </axisy2>
                                <axisx Title="Date" Interval="1">
                                    <MajorGrid Enabled="false"/>
                                </axisx>

                        <asp:Chart ID="Chart1" runat="server" Width="1000" BorderlineColor="Black" DataSourceID="SqlDataSource1">                    
                       <series>
                <asp:Series Name="Achieved %" XValueMember="date" YValueMembers="actual_value" Color="Plum" IsValueShownAsLabel="true" Palette="Pastel" ShadowColor="Bisque" > </asp:Series>             
             <asp:Series BorderWidth="2" Name="Target" ChartType="Line" Color="#00ff00" YValueMembers="target_value" BorderDashStyle="Dash"></asp:Series>
             <asp:Series BorderWidth="2" Name="Average %" ChartType="Line" Color="Brown" YValueMembers="average" BorderDashStyle="Dash"></asp:Series>
            </series>
         <Legends>
            <asp:Legend Name="DefaultLegend" Enabled="True" Docking="Bottom" />
         </Legends>
                     <chartareas>
                        <asp:ChartArea Name="ChartArea1">
                             <axisy Title="Achieved %">
                              <MajorGrid Enabled ="False" />
                    </axisy>
                    <axisy2 Title="Objective">
                                    <MajorGrid Enabled ="False" />
                    </axisy2>
                                <axisx Title="Date" Interval="1">
                                    <MajorGrid Enabled="false"/>
                                </axisx>

                        </asp:ChartArea>
                    </chartareas>
                </asp:Chart>

Sample Chart