locked
Gridview with Chart RRS feed

  • Question

  • User-883855585 posted

    I have the following gridview with a template column.  I am trying to display a chart with data specific to the row.  So each row has a medication with inventory data, then the template column would show the chart with usage info for that medication.

    Here is what I have at this point.  What I get is an empty chart in the header and each row only displays the word "chart".  This is a complete shot in the dark at trying to do this, so please don't destroy too much!

     Gridview:

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                            DataSourceID="SqlDataSource2" CellPadding="5" CellSpacing="4" 
                            EmptyDataText="No inventory for selected drug" ForeColor="#11554C" 
                            GridLines="None" HorizontalAlign="Center">
                            <RowStyle HorizontalAlign="Center" />
                            <Columns>
                                <asp:BoundField DataField="DrugID" HeaderText="DrugID" 
                                    SortExpression="DrugID" />
                                <asp:BoundField DataField="Drug" HeaderText="Drug" SortExpression="Drug" />
                                <asp:BoundField DataField="MedCar" HeaderText="MedCar" 
                                    SortExpression="MedCar" />
                                <asp:BoundField DataField="MedShelf" HeaderText="MedShelf" 
                                    SortExpression="MedShelf" />
                                <asp:BoundField DataField="Acudose" HeaderText="Acudose" 
                                    SortExpression="Acudose" />
                                <asp:BoundField DataField="Avg30DayDailyUsage" HeaderText="Avg Use - Last 14 Days" 
                                    ReadOnly="True" SortExpression="Avg30DayDailyUsage" />
                                <asp:BoundField DataField="TotalOnHand" HeaderText="OnHand (real-time)" 
                                    ReadOnly="True" SortExpression="TotalOnHand" />
                                <asp:BoundField DataField="DOH" HeaderText="Days On-Hand" ReadOnly="True" 
                                    SortExpression="DOH" DataFormatString="{0:n}" />
                                
                                <asp:TemplateField HeaderText="Usage">
                                    <ItemTemplate>
                                    
                                    </ItemTemplate>
                                </asp:TemplateField>
                                
                            </Columns>
                            <HeaderStyle Font-Underline="True" HorizontalAlign="Center" />
                        </asp:GridView>
    VB:
    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
            Dim connectionString As String
            Dim ds As New DataSet
            Dim stringxml As New StringBuilder
            'Dim days As Int32
            Dim drugid As String
    
            drugid = e.Row.Cells(0).Text
    
            connectionString = "Data Source=server;Initial Catalog=dbase;User ID=User;Password=xxxxx"
            stringxml.Append("<graph caption='' pallette='3' fontbold='1' canvasbgalpha='0' bgimagealpha='30' bgimage='hosp2.jpg' bgimagescale='100' outCnvBaseFontSize='7' showvalues='1' baseFontSize='7' useroundedges='1' bgcolor='FF5904,FFFFFF'>")
            Using conn As New SqlConnection(connectionString)
                conn.Open()
                Dim qry As New SqlCommand("select convert(datetime,a.t_date), convert(varchar,DATEPART(MM,a.t_date))+ '/' +convert(varchar,DATEPART(day,a.t_date))+ '/' +convert(varchar,Right(Year(a.t_date),2)) t_date, " & _
                "a.NetUsage Unit1 " & _
                "from fluid_usage a " & _
                "where " & _
                "convert(varchar,a.DrugDoseID) = '" & drugid & "' " & _
                "and a.t_date >= GETDATE()-14  order by convert(datetime,a.t_date) ", conn)
                Dim rst As SqlDataReader = qry.ExecuteReader()
    
                While rst.Read()
                    stringxml.AppendFormat("<set value='{0}'/>", rst("Unit1").ToString())
                End While
                stringxml.Append("<styles>  <definition> <style name='glow1' type='glow' color='FF5904' aplha='55' blurX='13' blurY='13' /><style name='B' type='animation' easing='bounce' param= '_xscale' duration='1' /> <style name='Bevel1' type='bevel' angle='0' /> <style name='Anim1' type='animation' param='_xScale' start='0' duration='1' />  <style name='Anim2' type='animation' param='_alpha' start='0' duration='1' easing='bounce' /> </definition> <application> <apply toObject='CANVAS' styles='Anim1, Anim2, Bevel1' /> ")
                stringxml.Append("<apply toObject='DATAPLOT' styles='Anim1, Anim2, Bevel1, B' />")
                stringxml.Append("<apply toObject='Canvas' styles='Anim1, Anim2, Bevel1, Glow1' />")
                stringxml.Append("</application> </styles>")
                stringxml.Append("</graph>")
    
                rst.Close()
                conn.Close()
            End Using
            e.Row.Cells(8).Text = FusionCharts.RenderChart("../FusionCharts/Line.swf?ChartNoDataText=No usage for selected drug.", "", stringxml.ToString(), "Unit1", "250", "100", _
                                                                 False, True)
        End Sub
    Thursday, January 4, 2018 5:36 PM

All replies

  • User-1838255255 posted

    Hi MongoI648,

    According to your description, i notice that you use the FusionCharts, as far as i know this is a paid service, so i can not debug your code in my side. But i found an example from the FusionCharts forum, please check:

    https://forum.fusioncharts.com/topic/1660-fusioncharts-inside-gridview/ 

    Also I hope you could debug your code step by step in your side, check which line code caused this issue. 

    if you could use chart control to replace it, about how to implement it inside gridview, please check this tutorial:

    http://www.dotnetawesome.com/2013/12/implement-chart-control-inside-gridview-using-aspnet.html 

    Best Regards,

    Eric Du

    Friday, January 5, 2018 7:06 AM
  • User-883855585 posted

    Here is update code using Chart control.  I do not get errors but it appears that it never makes it to the select statement.  Any ideas?

    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
           
            Dim connectionString As String
            Dim ds As New DataSet
            Dim stringxml As New StringBuilder
            Dim drugid As String
            
            connectionString = "Data Source=server;Initial Catalog=DB;User ID=User;Password=*****"
    
            Using conn As New SqlConnection(connectionString)
                conn.Open()
                Dim qry As New SqlCommand("select convert(datetime,a.t_date), convert(varchar,DATEPART(MM,a.t_date))+ '/' +convert(varchar,DATEPART(day,a.t_date))+ '/' +convert(varchar,Right(Year(a.t_date),2)) t_date, " & _
                    "a.NetUsage Unit1 " & _
                        "from fluid_usage a " & _
                        "where " & _
                        "convert(varchar,a.DrugDoseID) = '" & e.Row.Cells(0).ToString() & "' " & _
                        "and a.t_date >= GETDATE()-14  order by convert(datetime,a.t_date)", conn)
                Dim rst As SqlDataReader = qry.ExecuteReader()
                While rst.Read()
                    Dim chart As DataVisualization.Charting.Chart = CType(e.Row.FindControl("Chart2"), DataVisualization.Charting.Chart)
                    chart.Series.Add("Series1")
                    chart.Series("Series1").XValueMember = rst("Unit1").ToString()
                    chart.Series("Series1").YValueMembers = rst("t_date").ToString()
                    chart.Series("Series1").ChartArea = "ChartArea1"
    
                   End While
    
                rst.Close()
                conn.Close()
            End Using
    

    Tuesday, January 9, 2018 5:17 PM