anirbansarkar

Combination of bar and line chart

Recommended Posts

Hi,

I want to make a combination of bar chart and line chart where the data for one financial year will be portrayed with bar chart whereas the data for another financial year will be portrayed using a line chart. I am using PHP + MySQL .

Any help in this context will be highly appreciated.

Thanks in advance!!!

Share this post


Link to post
Share on other sites

Hi anirbansarkar,

 

 

 

this is a sample code quite same as you required.

 

 

 

 

 

 

 

<?php

 

#We've also used ../Includes/DBConn.php to easily connect to a database.

 

include("../Includes/DBConn.php");

 

 

 

# Include FusionCharts PHP Class

 

include('../Class/FusionCharts_Gen.php');

 

 

 

#Connect to the DB

 

$link = connectToDB();

 

 

 

# Create Column 3D + Line Dual Y-Axis Combination Chart

 

$FC = new FusionCharts("MSCombi2D","350","300");

 

 

 

# Set the relative path of the swf file

 

$FC->setSWFPath("../FusionCharts);

 

 

 

# Store chart attributes in a variable

 

$strParam="caption=Weekly Sales;subcaption=Comparison;xAxisName=Week;pYAxisName=Revenue;sYAxisName=Total Quantity;numberPrefix=$;sNumberSuffix= U";

 

 

 

# Set chart attributes

 

$FC->setChartParams($strParam);

 

 

 

#Sets the type of the Database

 

$FC->setDataBaseType("mysql");

 

 

 

# Add category names

 

$strQuery = "select distinct weekNames from Sales";

 

$result = mysql_query($strQuery);

 

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

 

 

 

 

 

# Add a new dataset with dataset parameters

 

$strQuery = "select weekNames,revenue from Sales WHERE financialyear='2010'";

 

$result = mysql_query($strQuery);

 

$FC->addDatasetsFromDatabase($result, "weekNames", "revenue");

 

 

 

 

 

# Add a new dataset with dataset parameters fpr previous year as line

 

$datasetParamArray=["renderAs=Line'];

 

$strQuery = "select weekNames,revenue from Sales WHERE financialyear='2009'";

 

$result = mysql_query($strQuery);

 

$FC->addDatasetsFromDatabase($result, "weekNames", "revenue",$datasetParamArray);

 

 

 

 

 

?>

 

 

 

<html>

 

<head>

 

<title>First Chart Using FusionCharts PHP Class</title>

 

<script language='javascript' src='../FusionCharts/FusionCharts.js'></script>

 

</head>

 

<body>

 

 

 

<?php

 

# Render Chart

 

$FC->renderChart();

 

?>

 

 

 

</body>

 

</html>

 

 

 

 

 

 

 

please change the code as per your exact requirement.

 

you may refer to these links-->

 

 

 

http://www.fusioncharts.com/Docs

 

 

 

http://www.fusioncharts.com/Docs/Contents/PHPClassAPI/Functions.html

 

 

 

http://www.fusioncharts.com/Docs/Contents/PHPClassAPI/CombinationChart.html

Edited by Guest

Share this post


Link to post
Share on other sites

Many thanks for the reply.

I tried executing the code with modifications as per my requirement but I cannot get rid of a syntax error in the line

<code>

$datasetParamArray=["renderAs=Line'];

</code>

The syntax error is :

Parse error: syntax error, unexpected '[' in <line and page details>

Kindly help!!!

Share this post


Link to post
Share on other sites

Thanks.

I am doing it on the lines of sample.zip with modifications as per my requirement.

The first series is showing in bar but the second series in line is still not appearing. However, no errors are also being shown!!

??

Share this post


Link to post
Share on other sites
Guest Madhumita

Hello,

Could you please attach the modified file along with a screnn-shot of the chart?

Apologies for the inconvenience. Awaiting your reply.

Share this post


Link to post
Share on other sites
Guest Basundhara Ghosal

Hi Anirban,

You are welcome.

Glad to help you.

Happy FusionCharting. :)

Share this post


Link to post
Share on other sites

Thanks once again!!!

Just a query - Hope I can add another line series to the existing combination chart if I want to chart a 3 year comparison data, i.e - combination of one bar chart and two line charts to chart the data of 3 financial years.

Regards.

Share this post


Link to post
Share on other sites
Guest Basundhara Ghosal

Hi Anirban,

You are welcome.

Yes, you can render one more line chart in the same combination chart just by adding one more dataset which has to be rendered as line.

Hope this helps. :)

Share this post


Link to post
Share on other sites

Hi,

I have plotted a combination chart using 3 financial years - one bar chart series and two line chart series.

The chart is appearing as per my requirement. The only thing which I require is that the chart should be a normal acombination chart and not a 3D one. I have used the 'MSCombi3D' chart type.

What do I actually need to use?

Any help will be highly appreciated.

Regards,

Anirban Sarkar

Share this post


Link to post
Share on other sites

Many thanks once again.

But from where will I get the required .swf file. I do not have it with me.

At the same time, I need to plot the data points in the line chart. What do I need to do for that?

Thanks and regards!!! 

Share this post


Link to post
Share on other sites

Many thanks once again!!!

I have been able to plot the 2D graph with the .swf file provided. Is there any way by which I can suppress the values appearing against every plot points?

Thanks and regards.

Share this post


Link to post
Share on other sites

Many thanks once again!!!

I have been able to suppress the data values in the bar chart by using the dataset attribute showValues to 0. However the same is not happening in case of line chart.

I am using the following code:

<CODE>

$FC_bbgs->addDataset($last_1_fin_yr_desc,"renderAs=Line","showValues=0");

</CODE>

Where am I going wrong?

Thanks and regards!!!

Share this post


Link to post
Share on other sites
Guest Basundhara Ghosal

Hi Anirban,

Happy to help you. :)

In case you wish not to display the values of the line plot, please try setting the "showValues" to '0' in the <lineset> element.

Hope this helps. :)

Share this post


Link to post
Share on other sites

Hi,

I am having problems when generating a pie chart with links.

I have generated the pie chart and want to make every individual slice a link which in turn will redirect me to another page.

Please refer to the function getPoDueXML in the attached file. The problem which I am facing is that the chart is not getting generated and it is showing 'Invalid XML data'.

Also having problems regarding the suppressing of data values in the line chart which I had posted earlier.

Thanks and regards!!!

ChartGen.zip

Share this post


Link to post
Share on other sites

Hi anirbansarkar,

 

could you please try this code in your function

 

@$strXML .= "<set label='" . escapeXML($wing_name,$forDataURL) . "' value='" . $row_tot_amt['tot_po_due'] . "' isSliced='" . $slicedOut . "' link='" . urlencode($strLink) . "' />";

Share this post


Link to post
Share on other sites
Guest Basundhara Ghosal

Hi Anirban,

We are happy that your issue is resolved.

Happy FusionCharting and keep FusionCharting. :)

Share this post


Link to post
Share on other sites

Hi,

I have not yet been able to suppress the data values in the line chart. As per your suggestion I tried setting the showValues attribute to 0 in the <lineset> element but I feel that I am going wrong somewhere.

In case of the bar chart I am using the undergiven code which is working fine:

<code>

$FC->addDataset($row_fin_yr_desc['fin_desc'],'showValues=0');

</code>

Following the above concept, I tried the following in case of line chart which however is not working:

<code>

$FC->addDataset($last_1_fin_yr_desc,"renderAs=Line",'showValues=0');

</code>

Where am I going wrong?

Any help will be appreciated.

Thanks and regards!!!

Share this post


Link to post
Share on other sites
Guest Basundhara Ghosal

Hi Anirban,

Could you please specify the name of the swf file that you are using for this?

Awaiting your reply. :)

Share this post


Link to post
Share on other sites

I want to plot the data of last 3 financial years quarter wise in a column chart. I want to plot the summation of every quarter for the last three financial years, including the current financial year - 2009/2010. The graph will be as follows:

In the X axis there will be 3 points for FY-0708, FY-0809 and FY-0910 respectively. Against every financial year point there will be 4 bars (each bar representing a particular quarter of the financial year). So overall, there will be 4 bars against every financial year and 12 bars in total subject to availability of data.

I have tried doing the same but feel that I am going wrong somewhere. I am uploading a zip file with the code snippet. The code only contains the script for one financial year. Hope this code can be replicated for the other two financial years.

Any help will be highly appreciated.

Thanks and regards.

chart.zip

Share this post


Link to post
Share on other sites

Hi anirbansarkar,

 

as per your requirement you have to add four quarters of financial year as categories, then add latest 3 years as dataset with it's quarters as set within it.

 

 

 

for details you can refer to this link http://www.fusioncharts.com/docs/Contents/PHPClassAPI/Functions.html#dbhandling

 

 

 

hope this will help you:)

Edited by Guest

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