Sign in to follow this  
azrarayne

Rendering Multiple Charts on page - only one shows up

Recommended Posts

Hi!  I'm new to FusionCharts and can't seem to find any information on this subject.  I have a web page that I need to render up to 30 small charts on.  I have the code working, but it will only render the first chart.  It doesn't matter which chart I try to load up first, the next charts do not load.  Is there a way to render multiple charts on a single page?  My code is below.  ChartName, ExportFileName, ChartType, and DivToAddTo are all strings passed in by each chart method that I am loading.  I have verified that I am passing in a different div name each time.  I also pass in a data set called mainData that I loop through to build the bar string.  This is all done in vb.net in the code behind of my page. 

 

            Dim sbXml As New System.Text.StringBuilder
            sbXml.Append("<chart  caption='" & chartName & "' " &
                             " canvasBorderColor='#ABADB3' " &
                             " canvasBorderThickness='1' " &
                             " xaxisname='' " &
                             " showvalues='1' " &
                             " animation='1' " &
                             " yaxisname='' " &
                             " showBorder='0' " &
                             " bgColor='#ffffff' " &
                             " chartLeftMargin='10' " &
                             " chartTopMargin='10' chartRightMargin='25'  " &
                             " chartBottomMargin='20' " &
                             " toolTipBorderColor='#ABADB3' " &
                             " zeroPlaneColor='#f9f9f9' " &
                             " zeroPlaneThickness='1'   " &
                             " showAlternateHGridColor='1' " &
                             " forceXAxisValueDecimals='1' " &
                             " forceYAxisValueDecimals='1' " &
                             " forceDecimals='1' " &
                             " showPlotBorder='0'   " &
                             " usePlotGradientColor='0' " &
                             " plotHoverEffect='1'   plotFillAlpha='100'    " &
                             " showShadow ='0' " &
                             " labelDisplay='wrap' " &
                             " numdivlines='5' " &
                             " exportFileName='" & exportFileName & "' exportEnabled ='1'  exportAtClient ='0' exportAction ='save'  exportShowMenuItem='0' " &
                             " exportHandler ='" & ConfigurationManager.AppSettings.Item("FusionChartsURL") & "'" &
                             " placevaluesInside='1' rotateValues='0' valueFontSize='11'" &
                             " valueFontBold='0' " &
                             " valueFontColor='#ffffff'  " &
                             " decimals='1' showLegend='1' legendBgColor='#FFFFFF' legendShadow='0' legendBorderColor='#FFFFFF' paletteColors='#5A3588,##ff9e1b,#ff9e1b'>")
                             
                For Each item As ContractValue In mainData

                    Dim toolText As String 'set equal to name and value

                    toolText = item.Name & " - " & item.Value

                    'add category
                    categoryString.Append("<category label ='" & item.Name & "' />")

                    Dim value As Double = 0

                    Try
                        value = item.Value
                    Catch ex As Exception
                        'No error, set to blank
                    End Try

                    bar1String.Append("<set value='" & If(value <> 0, value.ToString, String.Empty) & "' color='#ff9e1b' tooltext='" & toolText & "'/>")
                Next
                
 				sbXml.Append("<categories>")
                sbXml.Append(categoryString.ToString)
                sbXml.Append("</categories>")

                sbXml.Append("<dataset  seriesname='My Average'>")
                sbXml.Append(bar1String.ToString)
                sbXml.Append("</dataset>")
               
                sbXml.Append("</dataset>")

                sbXml.Append("</chart>")

                Dim fusionChart As New Chart(chartType, divToAddTo, "600", "280", "xml", sbXml.ToString)
             
                Dim sRenderedChart As String = fusionChart.Render()
                Dim sStartScriptTag As String = "<script type=""text/javascript"">"
                Dim sEndScriptTag As String = "</script>"
                Dim sJsCode As String = sRenderedChart.Substring(sRenderedChart.IndexOf(sStartScriptTag) + sStartScriptTag.Length, sRenderedChart.IndexOf(sEndScriptTag) - sRenderedChart.IndexOf(sStartScriptTag) - sStartScriptTag.Length) & ";"
                ScriptManager.RegisterStartupScript(Me, Me.GetType, "JSCode", sJsCode, True)

 

Share this post


Link to post
Share on other sites

We were able to get this figured out.  We just had to build the sjsCode as a global variable and add to it for every chart, then call the ScriptManager.RegisterStartupScript once after all of the charts were rendered.  

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this