how do i overlay a "line chart" on a "point chart" using asp.net charting toolkit?
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 grap开发者_运维技巧h?
Needed to create a different series within the ChartArea and set ChartType = "Line"
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
精彩评论