Sign in to follow this  
Rahul Kumar

PHP API + MySQL Multi-series chart

Recommended Posts

Currently I am able to use single series charts without a problem:

 

 

 

 

 

$FC = new FusionCharts("Column2D","250","250");

 

 

 

 

 

$FC2->setSWFPath("../charts/fusioncharts/");

 

 

 

 

 

$strParam="caption=Type;bgColor=FFFFFF;borderColor=FFFFFF;xAxisName=Type;yAxisName=Quantity;decimalPrecision=0;labelDisplay=ROTATE;slantLabels=1";

 

 

 

# Set chart attributes

 

$FC->setChartParams($strParam);

 

 

 

$result = $r->query("SELECT iType, COUNT(iType) as total FROM i GROUP BY iType");

 

 

 

 

 

if ($result)

 

{

 

$FC->addDataFromDatabase($result, "total", "iType");

 

}

 

 

 

 

 

I am trying to create a multi series chart from the following table.

 

 

 

User Type Type Code

 

Type1 A1

 

Type1 A2

 

Type1 A2

 

Type2 A1

 

Type2 A1

 

Type2 A1

 

Type3 A1

 

Type3 A2

 

Type3 A3

 

Type3 A3

 

Type4 A3

 

Type5 A1

 

 

 

The user type is meant to be the categories and the Each code should be a series for each user type.

 

 

 

I want to end up with a graph which shows how many of each Code is for each type of user.

 

 

 

 

 

 

 

 

 

Any help in setting up a multi-series chart from a database would be great.

Share this post


Link to post
Share on other sites

Hi,

 

 

 

I am newby to this forum and found FusionCharts quite interesting. :)

 

 

 

I thought this might help you somewhat?

 

Ref.-http://www.fusioncharts.com/docs/?PHP_DB.html

 

 

 

Just a thought, but I think you would have to conform to the Multi-series XML format for the respective Multi-series chart you are using for this.

 

 

 

Have a nice day!

Edited by Guest

Share this post


Link to post
Share on other sites

So you dont think its possible to use the PHP Class for a multi-series chart?

 

 

 

If you see the attached file this is basically what I want to do.

 

 

 

 

 

# Create Column3D chart Object

 

$FC = new FusionCharts("MSColumn3D","250","250");

 

# set the relative path of the swf file

 

$FC->setSWFPath("../seracharts/fusioncharts/");

 

 

 

# Store chart attributes in a variable

 

$strParam="caption=Weeks;bgColor=FFFFFF;borderColor=FFFFFF;decimalPrecision=0;paletteColors=FF5904,0372AB,FF0000;baseFontSize=8";

 

 

 

$FC->addCategory("Manager");

 

$FC->addCategory("Engineer");

 

$FC->addCategory("Teacher");

 

$FC->addCategory("Driver");

 

 

 

# Create a new dataset

 

$FC->addDataset("Code 1");

 

# Add chart values for the above dataset

 

$FC->addChartData("10");

 

$FC->addChartData("9");

 

$FC->addChartData("16");

 

$FC->addChartData("11");

 

 

 

# Create second dataset

 

$FC->addDataset("Code 2");

 

# Add chart values for the second dataset

 

$FC->addChartData("10");

 

$FC->addChartData("8");

 

$FC->addChartData("6");

 

$FC->addChartData("4");

 

 

 

# Create third dataset

 

$FC->addDataset("Code 3");

 

# Add chart values for the third dataset

 

$FC->addChartData("12");

 

$FC->addChartData("14");

 

$FC->addChartData("6");

 

$FC->addChartData("7");

post-8333-128441582475_thumb.jpg

Edited by Guest

Share this post


Link to post
Share on other sites

So my first category "Manager" Would appear like this in the database table

 

 

 

Manager Code 1

 

Manager Code 1

 

Manager Code 1

 

Manager Code 1

 

Manager Code 1

 

Manager Code 1

 

Manager Code 1

 

Manager Code 1

 

Manager Code 1

 

Manager Code 1

 

Manager Code 1

 

Manager Code 2

 

Manager Code 2

 

Manager Code 2

 

Manager Code 2

 

Manager Code 2

 

Manager Code 2

 

Manager Code 2

 

Manager Code 2

 

Manager Code 2

 

Manager Code 3

 

Manager Code 3

 

Manager Code 3

 

Manager Code 3

 

Manager Code 3

 

Manager Code 3

 

Manager Code 3

 

Manager Code 3

 

Manager Code 3

 

Manager Code 3

 

Manager Code 3

 

 

 

I would need the query to count the number of each code for each category

Edited by Guest

Share this post


Link to post
Share on other sites
Guest Basundhara Ghosal

Hi,

Could you please let us know whether your issue is resolved?

Awaiting your reply.

Share this post


Link to post
Share on other sites

No I still haven't found a solution to this issue.

 

 

 

I would really love an example which uses an sql query to count data for a multi-series chart and then display it with the PHP CLASS

 

 

 

For my specific example I am trying to get the code to display the categories as the x axis for the table. For this I was using the DISTINCT function so that it pulls all of the different types.

 

 

 

Then I am trying group and count the results from another field in the table, so that each different type of result is counted and then displayed as a different series.

 

 

 

This example I feel is getting close. I just need to get it to identify each different type of result as a seperate dataset and then count them for each category.

 

 

 

http://www.fusioncharts.com/docs/?/PHPClassAPI/MultiSeriesChart.html

Edited by Guest

Share this post


Link to post
Share on other sites

Hi,

Could you please try using the following code?

Considering your table (ABC) as:

  Type  Code

Manager Code 1

Manager Code 1

Manager Code 1

Manager Code 1

Manager Code 1

Manager Code 1

Manager Code 1

Manager Code 1

Manager Code 1

Manager Code 1

Manager Code 1

Manager Code 2

Manager Code 2

Manager Code 2

Manager Code 2

Manager Code 2

Manager Code 2

Manager Code 2

Manager Code 2

Manager Code 2

Manager Code 3

Manager Code 3

Manager Code 3

Manager Code 3

Manager Code 3

Manager Code 3

Manager Code 3

Manager Code 3

Manager Code 3

Manager Code 3

Manager Code 3

 

$strQuery = "select distinct TYPE from ABC";

$result = mysql_query($strQuery);

$FC->addCategoryFromDatabase($result, "TYPE");

$strQuery = "SELECT CODE, COUNT(CODE) as total FROM ABC GROUP BY CODE";

$result = mysql_query($strQuery);

$FC->addDatasetsFromDatabase($result, "CODE","total");

Please let us know whether it is working or not.

Share this post


Link to post
Share on other sites

Hi, thankyou for the reply.

 

 

 

It appears that it almost worked.

 

 

 

 

 

The categories display correctly as the different results of TYPE along the bottom of the chart.

 

 

 

However, the results of the CODE are being totaled and displayed for the first category.

 

 

 

It is definitely feeling closer the results just need to be grouped by the TYPE

 

 

 

It looks something like the attached file.

post-8333-128441582558_thumb.jpg

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