0

I currently have a point chart using the asp.net charting toolkit, but would like to place a line of best fit on the same chart. Assuming that I know how to calculate the equation for the line (y=mx+b), how would I overlay this in the same graph?

locoboy
  • 38,002
  • 70
  • 184
  • 260

2 Answers2

0

Needed to create a different series within the ChartArea and set ChartType = "Line"

locoboy
  • 38,002
  • 70
  • 184
  • 260
0

I hope this code will help you:

<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

Matheus Lacerda
  • 5,983
  • 11
  • 29
  • 45