jgcrossman2 Report post Posted March 28, 2013 I would like to add a sloping line in an XY Chart. It would not be the same as a regression line because that would give each point an equal weighting. I have used the $FC->addTrendLine function with a different startValue and endValue as a temporary fix. However, I would like to draw a line with points that I define. I found this in an old post: <dataset seriesName='Mean' color='009900' anchorSides='3' anchorRadius='4' anchorBgColor='D5FFD5' anchorBorderColor='009900' drawLine='1' anchorAlpha='0'> <set y='2.4' x='21' /> <set y='3.5' x='32' /> <set y='2.5' x='43' /> <set y='4.1' x='48' /> <set y='3.5' x='50' /> <set y='4.6' x='56' /> <set y='4.8' x='59' /> <set y='4.9' x='73' /> <set y='4.6' x='89' /> <set y='4.2' x='93' /> </dataset> How would I turn that into $FC-> syntax that both FusionCharts and PHP can understand? I start with this: $FC->addDataSet("seriesName=P/E;drawLine=1;color=00FF00;thickness=2"); And I assume that the problem is in the addDataChart lines. I have tried a few variations on: $FC->addChartData("y=0", "x=0"); $FC->addChartData("y=6", "x=40"); but to no avail. Any suggestions would be appreciated. Here is the chart I am working on so you can see what is going on: http://www.fund-king.com/requests/XYChart1.php?etf=XLV Share this post Link to post Share on other sites
Guest Sashibhusan Report post Posted March 28, 2013 Hi, As you have mentioned, the "addChartData()" method is not provided with correct arguments. The correct syntax for "addChartData()" is: addChartData(string $value[, string $params, string $vlineParams]) Please note that for Scatter Chart the x value should be passed to value parameter, y value should be passed along with other dataplot attributes (if any) as a list of delimiter separated attributes. For example, addChartData("40","y=6;alpha=80") For more information on "FusionCharts PHP Class API Reference > List of Functions", please follow the link below: http://docs.fusioncharts.com/charts/contents/?guide-for-web-developers/fusioncharts-php-class/Functions.html Hope this helps! Share this post Link to post Share on other sites
jgcrossman2 Report post Posted March 29, 2013 The solution you give only makes more scatter plot points. Maybe I was not clear, I want to draw a line through the chart as well. Can that be done? Share this post Link to post Share on other sites
Sanjukta Report post Posted March 29, 2013 The solution you give only makes more scatter plot points. Maybe I was not clear, I want to draw a line through the chart as well. Can that be done? Hi, Could you please set "drawLine" attribute to '1' in the <dataset> element where you wish to draw the line connecting the scatter plots? Ex: <dataset ... drawLine='1'> In case we are unable to comprehend your query, please provide us with a screenshot of your requirement. Hope this helps. Share this post Link to post Share on other sites
jgcrossman2 Report post Posted March 30, 2013 OK, it is definitely close but just not quite there. This is what I want: I am starting here: http://www.fund-king.com/requests/XYChart1.php?etf=XLV The key part of the code is: while ($row1 = mysql_fetch_row($result1)) { echo $FC->addDataset("$row1[0]"); echo $FC->addChartData("$row1[4]","y=$row1[3]");} //$FC->addDataSet("drawLine=1"); //$FC->addChartData("0", "y=0"); //$FC->addChartData("40", "y=6");?> <html> <head> <title>Scatter Chart : FusionCharts PHP Class</title> <script language="javascript" src="../FusionCharts/FusionCharts.js"></script> </head> <body> <?php # Render Chart $FC->renderChart(); ?> <h3>Equities List</h3> <table border=0> <tr><td>Ticker</td><td>Company Name</td><td>Price/Book</td><td>Return on Equity</td></tr> <?php while ($row2 = mysql_fetch_row($result2)) { echo "<tr><td><a href = '../steam/InfoSteam.php?stock_ticker=".$row2[0]."' target='_blank'>".$row2[0]."</a></td><td>".$row2[1]."</td><td>".$row2[2]."x</td><td>".$row2[3]."%</td></tr>"; } ?> </body> </html> As you can see, I have commented out my attempt at drawing a line. Here is the result: When I add in the following code after the code that builds the scatter points from my database: while ($row1 = mysql_fetch_row($result1)) { echo $FC->addDataset("$row1[0]"); echo $FC->addChartData("$row1[4]","y=$row1[3]");} $FC->addDataSet("drawLine=1"); $FC->addChartData("0", "y=0"); $FC->addChartData("40", "y=6");?> <html> <head> <title>Scatter Chart : FusionCharts PHP Class</title> <script language="javascript" src="../FusionCharts/FusionCharts.js"></script> </head> <body> <?php # Render Chart $FC->renderChart(); ?> <h3>Equities List</h3> <table border=0> <tr><td>Ticker</td><td>Company Name</td><td>Price/Book</td><td>Return on Equity</td></tr> <?php while ($row2 = mysql_fetch_row($result2)) { echo "<tr><td><a href = '../steam/InfoSteam.php?stock_ticker=".$row2[0]."' target='_blank'>".$row2[0]."</a></td><td>".$row2[1]."</td><td>".$row2[2]."x</td><td>".$row2[3]."%</td></tr>"; } ?> </body> </html> I get this result: I have added in the red boxes and purple lines. I have saved this as: http://www.fund-king.com/requests/XYChart2.php?etf=XLV If you click on the datapoint in the legend box, you will notice that both points on the chart are selected so we are frustratingly close to the solution. What I need is some way to tell the chart that we need a line between these two points (0,0) and (40,6) as endpoints rather than having the chart pick up "drawLine=1" as a label for two scatter points on the chart. Perhaps the first line $FC->addDataSet("drawLine=1"); needs something more to distinguish it as a different element in the chart. Share this post Link to post Share on other sites
Swarnam Report post Posted March 30, 2013 Hey, Can you please try using the below code? $FC->addDataset("DrawLine","drawLine=1"); Hope this helps. Share this post Link to post Share on other sites
jgcrossman2 Report post Posted March 30, 2013 Thank you very much. "DrawLine" before "drawLine=1" was the missing element. Now it works just as I wanted. I decided to experiment and found that you do not need "DrawLine" in particular. Any label will do. If you look at this example, I have changed out "DrawLine" with "15x P/E" (which is more relevant in this case). http://www.fund-king.com/requests/XYChart2.php?etf=XLV Again, thank you for you patience with a newbie like myself. Regards, John Share this post Link to post Share on other sites