The code is pretty simple:
using (SqlConnection conn = new SqlConnection("OMG look a connection string")) { using (SqlCommand cmd = new SqlCommand("SELECT xValue, yValue FROM chartPoints")) { try { conn.Open() using (SqlDataReader rdr = cmd.ExecuteReader()) { chartSellThru.Series["QTDRatio"].Points.DataBindXY(rdr, "xValue", rdr, "yValue"); } } catch(Exception ex) {
You can also set this command as SelectCommand for the SqlDataSource and bind it to the chart, and then select points using XValueMember and YValueMembers in the same way as you did before
<asp:SqlDataSource runat="server" ID="dsLinePoints" ConnectionString="OMG look a connection string" SelectCommand="SELECT xValue, yValue FROM chartPoints" /> <asp:Chart ID="chartSellThru" runat="server" Height="400px" Width="1200px" DataSourceID="dsLinePoints"> <Series> <asp:Series Name="ActualsQTD"> </asp:Series> <asp:Series Name="ForecastQTD"> </asp:Series> <asp:Series Name="QTDRatio" ChartType="Line"> </asp:Series> <asp:Series Name="TargetAttain" ChartType="Line"> </asp:Series> </Series> <ChartAreas> <asp:ChartArea Name="SellThruChartArea"> </asp:ChartArea> </ChartAreas> </asp:Chart> chartSellThru.Series["QTDRatio"].XValueMember = "xValue"; chartSellThru.Series["QTDRatio"].YValueMembers = "yValue";
source share