We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Bind 2 SQL DataSource to a single chart

Hi,

Is it possible to bind 2 differant SQL DataSources to a single chart? So for each <ej:series> you would have a different SqlDataSource

<ej:Series Name="DataSource1" XName="DataSource1" YName="DataSource1"></ej:Series>
<ej:Series Name="DataSource2" XName="DataSource2" YName="DataSource2"></ej:Series>
<asp:SqlDataSource ID="DataSource1" runat="server" ConnectionString="Connection" SelectCommand="QUERY"></asp:SqlDataSource>
<asp:SqlDataSource ID="DataSource2" runat="server" ConnectionString="Connection" SelectCommand="QUERY"></asp:SqlDataSource>

1 Reply

SK Sanjith Kesavan Syncfusion Team May 17, 2016 12:39 PM UTC

Hi Cory, 

Thanks for contacting Syncfusion support. We have analyzed your query. Currently we are not having support for binding 2 different SQL datasources to a single chart. But we can bind the table which containing multiple columns as the datasource for the chart and we can use these different column values for series. Please find the below code example. 

[ASPX] 

<asp:SqlDataSource ID="SqlData" runat="server"  
            ConnectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\Incident\Samples\17-5-16\ASP\WebApplication2\WebApplication2\App_Data\Windowsformdata.mdf;Integrated Security=True;Connect Timeout=30" 
            SelectCommand="SELECT * FROM [table2]"> 
        </asp:SqlDataSource> 

In the above code, we have get the data from “table2”. Table2 is containing 3 columns(x,y,y1).  

<ej:Chart runat="server" DataSourceID="SqlData" XName="x" YName="y" ID="ChartSample">    
         <PrimaryXAxis ValueType="Category" LabelPlacement="BetweenTicks" IntervalType="Days" /> 
        <Series> 
            <ej:Series XName="x" YName="y" Type="Column">   
                <Tooltip Visible="true"></Tooltip>           
            </ej:Series> 
            <ej:Series XName="x" YName="y1" Type="Column"> 
                <Tooltip Visible="true"></Tooltip> 
            </ej:Series> 
             
        </Series>        
    </ej:Chart> 

In the above code, we have bound the “table2” as datasource for the chart using its ID in “DataSourceID”. For the first series we have bound x as  xname and y as yname and for the second series we bound x as xname and y1 as yname. Now the chart will render like below.  

 
In the below link, we have attached sample for your reference. 

Regards, 
Sanjith. 


Loader.
Up arrow icon