FusionCharts Free,  Plotting data from a database (more than two tables)

Posted on 2008-10-23
Last Modified: 2013-12-25
Hi I have been trying to show data in a bar graph.

The Data:

I have 8 Table with the same Cloumns:

The names of the tables are:
   (Act, COW, DSafety, Environment, HouseKeep, IntManage, RiskAssess, Security)

The Cloumns for the this 8 tables are as follows:
  AutoID (bigint, 8)
  QuestionNum (Int, 4)
  QuestionText (varchar)
  Answer (int, 4)
  TASAFormID (bigint, 8)
  dbPosition (int,4)

Please Note: the "dbPostion" is the number of which the table should be, for example;
    The Table "Act" has every single record has the value of 1 in the dbPostion Field
    "COW" has every single record has the value of 2 in the dbPostion Field
    "DSafety" has every single record has the value of 3 in the dbPostion Field
     and so on......

For each of those 8 tables I want them to each have there own bar (so there would be 8)

As you well see from the code snippet I want the table to only pull the records from each table only where the "TASAFormID " = A drop down list selected value

The data of which I want to show for the graph is the The percentage of the Postive answers
The Answers are declared in the "Answer" field and have the values of:
Positive = "1"
negitive = "0"

AS you can see from the code behide code that there is another table called "tdQuestionElements"
Where I am getting the bottom titles from the coloumn "Element"

The Thing is
It is showing 8 Bars with the rights Titles, however it is showing the SAME answer value (the first table "Act" value)  for each one

I even though I have it showing the Percentage sign for the the values it is doing a SUM.
I need it to;
If the table has got 10 questions and 7 have the answer value "1" I need it to show 70% instead of 7%

So i need to be able to calculate the percentage of the answers of each Table however each table has diffrent number of answers and I wont know how many there are untill it gets the value from the dropdown list

there are propley spelling mistakes as Iam in a rush lol
Imports System.Data.SqlClient
Imports DataConnection
Imports InfoSoftGlobal
Partial Class TASA_TASA
    Inherits System.Web.UI.Page
    Public jsVarString As String
    Public indexCount As String
    Public Sub GetjsVar()
        jsVarString = ""
        Dim oRs As DataConnection.DbConn, strQuery As String
        indexCount = 0
        strQuery = "select * from tdQuestionElements"
        oRs = New DataConnection.DbConn(strQuery)
        While oRs.ReadData.Read()
            indexCount = indexCount + 1
            jsVarString = jsVarString & vbTab & vbTab & "data[" & indexCount & "] = new Array();" & vbCrLf
            strQuery = "select * from COW" _
            & " union select * from Act" _
            & " union " _
            & "select * from DSafety" _
            & " union " _
            & "select * from HouseKeep" _
            & " union " _
            & "select * from IntManage" _
            & " union " _
            & "select * from RiskAssess" _
            & " union " _
            & "select * from Security  order by dbPosition" & vbCrLf
            Dim oRs2 As New DataConnection.DbConn(strQuery)
            While oRs2.ReadData.Read()
                jsVarString = jsVarString & vbTab & vbTab & "data[" & indexCount & "].push(new Array('" & oRs2.ReadData("Answer").ToString() & "));" & vbCrLf
            End While
        End While
    End Sub
    Public Function CreateChart() As String
        Dim strXML As String, strQuery As String
        indexCount = 0
        strXML = "<graph caption='percentage Compilance' subCaption='' decimalPrecision='0' showNames='1' numberSuffix='%25 ' pieSliceDepth='20' formatNumberScale='0' >"
        strQuery = "select * from tdQuestionElements"
        Dim oRs As New DataConnection.DbConn(strQuery)
        While oRs.ReadData.Read()
            indexCount = indexCount + 1
            strQuery = "select sum(Answer) as TotOutput from Act where TasaFormID = " & DropDownList1.SelectedValue _
            & " union " _
            & "select sum(Answer) as TotOutput from COW where TasaFormID = " & DropDownList1.SelectedValue _
            & " union " _
            & "select sum(QuestionNum) as TotOutput from DSafety where TasaFormID = " & DropDownList1.SelectedValue _
            & " union " _
            & "select sum(QuestionNum) as TotOutput from HouseKeep where TasaFormID = " & DropDownList1.SelectedValue _
            & " union " _
            & "select sum(QuestionNum) as TotOutput from IntManage where TasaFormID = " & DropDownList1.SelectedValue _
            & " union " _
            & "select sum(QuestionNum) as TotOutput from RiskAssess where TasaFormID = " & DropDownList1.SelectedValue _
            & " union " _
            & "select sum(QuestionNum) as TotOutput from Security where TasaFormID = " & DropDownList1.SelectedValue
            Dim oRs2 As New DataConnection.DbConn(strQuery)
            strXML = strXML & "<set name='" & oRs.ReadData("dbPosition").ToString() & "' value='" & oRs2.ReadData("TotOutput").ToString() & "' link='javascript:updateChart(" & indexCount & ")'/>"
            oRs2 = Nothing
        End While
        strXML = strXML & "</graph>"
        oRs = Nothing
        Return FusionCharts.RenderChart("../FusionCharts/FCF_Column3D.swf", "", strXML, "", "650", "300", False, True)
    End Function
End Class
Heres the ASPX Head section code for the chart
	<script language="Javascript" src="../FusionCharts/FusionCharts.js">
		//You need to include the above JS file, if you intend to embed the chart using Javascript.
		//Embedding using Javascripts avoids the "Click to Activate..." issue in Internet Explorer
		//When you make your own charts, make sure that the path to this JS file is correct. Else, you would get Javascript errors.
	<script language="Javascript" >
		//Here, we use a mix of server side script (ASP) and Javascript to
		//render our data for factory chart in Javascript variables. We'll later
		//utilize this data to dynamically plot charts.
		//All our data is stored in the data array. From ASP, we iterate through
		//each recordset of data and then store it as nested arrays in this data array.
		var data = new Array();
		//Write the data as Javascript variables here
		 //The data is now present as arrays in Javascript. Local Javascript functions
		 //can access it and make use of it. We'll see how to make use of it.
		 * updateChart method is invoked when the user clicks on a pie slice.
		 * In this method, we get the index of the factory, build the XML data
		 * for that that factory, using data stored in data array, and finally
		 * update the Column Chart.
		 *	@param	factoryIndex	Sequential Index of the factory.
		function updateChart(factoryIndex){
			//defining array of colors
			//We also initiate a counter variable to help us cyclically rotate through
			//the array of colors.
			var FC_ColorCounter=0;
			//var arr_FCColors= new Array(20);
			var arr_FCColors= new Array("1941A5" , "AFD8F8", "F6BD0F", "8BBA00", "A66EDD", "F984A1", "CCCC00", "999999", "0099CC", "FF0000", "006F00", "0099FF", "FF66CC", "669966", "7C7CB4", "FF9933", "9900FF", "99FFCC", "CCCCFF", "669900");
			//Storage for XML data document
			var strXML = "<graph caption='Factory " + factoryIndex  + " Output ' subcaption='(In Units)' xAxisName='Date' decimalPrecision='0' rotateNames='0' >";
			//Add <set> elements
			var i=0;
			for (i=0; i<data[factoryIndex].length; i++){
				strXML = strXML + "<set name='" + data[factoryIndex][i][0] + "' value='" + data[factoryIndex][i][1] + "' color='"+ arr_FCColors[++FC_ColorCounter % arr_FCColors.length] +"' />";
			//Closing graph Element
			strXML = strXML + "</graph>";
			//Update it's XML
Heres the ASPX BODY section code for the chart

Open in new window

Question by:dannytammyuk
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment

Accepted Solution

dannytammyuk earned 0 total points
ID: 22795745
I have found another way around this

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question