how to export fusionchart in PHP - php

I want to export fusionchart to images or pdf , what should I add? without using a third party
<?php
*//koneksi database*
include "config/koneksi.php";
error_reporting(E_ALL ^ (E_NOTICE | E_DEPRECATED));
include "config/koneksi.php";
include("config/class/FusionCharts_Gen.php");
$pencarian=$_POST['pencarian'];
$bulan=$_POST['bulan'];
$barang_aset=$_POST['barang_aset'];
?>
<html>
<head>
<title>First Chart Using FusionCharts PHP Class</title>
<script language='javascript' src='assets/js/FusionCharts.js'></script>
</head>
<body>
<?php
# Include FusionCharts PHP Class
# Create object for Column 3D chart
$FC = new FusionCharts("column3d","900","450");
# Setting Relative Path of chart swf file.
$FC->setSwfPath("Charts/");
# Store chart attributes in a variable
$strParam="caption=Grafik Jumlah Inventaris dan Aset Berdasarkan Kategori";
# Set chart attributes
$FC->setChartParams($strParam);
$kategori = mysql_query("SELECT id_kategori, nama_kategori FROM kategori");
//$tracking = mysql_query("SELECT Nama_Karyawan FROM master_karyawan WHERE Kode_Nama_Cabang='SRJ' AND Category_Tracking='sales'");
while ($r_kat = mysql_fetch_array($kategori)){
$id_kat = $r_kat['id_kategori'];
$kat = $r_kat['nama_kategori'];
$counter1 = 0;`enter code here`
**What do I need to add to add exportEnabled in this fusionchart**
//$total = mysql_num_rows(mysql_query("SELECT IdKat,TglTerjual FROM penjualan_buku WHERE IdKat='$kat' AND LEFT(TglTerjual,4)='2012' AND MID(TglTerjual,6,2)='02'"));
$total = mysql_query("SELECT id_kategori, nama_barang FROM barang WHERE id_kategori='$id_kat' and nama_barang like '%$_POST[barang_aset]%'and MONTH(tanggal_status) like '%$_POST[bulan]%' and status like '%$_POST[pencarian]%' ");
$counter1++;
//$persentase = ($total!=0 || $review !=0)?($review / $total) *100:0;
$total = mysql_num_rows($total);
# add chart values and category names
$FC->addChartData("$total","name=<a href='jmlaset.php?id=$id_kat'>$kat</a>");
}
# Render Chart
$FC->renderChart();
?>
</body>
</html>
How do I add an export function in this fusionchart?

Your php wrapper class for FusionCharts is not validating with the latest wrapper class please see the link
you can also export chart through FusionCharts export server by setting the attribute exportEnabled to 1. This will use their export server and will download the image at your end.
If you want to create your own export server, you can use the FusionCharts' distributable export handler. You can get useful information from this link but it uses two third party api ImageMagick and InkScape to convert SVG to required image formats. You need to install this dependencies at your end.

Related

How to display data in ckeditor from mysql in PHP

I am new in this field, I used ckeditor but I don't know how to display data in ckeditor through mysql..
My code is
$CKeditor = new CKeditor();
$CKeditor->BasePath = 'manage-site/';
$CKeditor->config['filebrowserBrowseUrl'] = 'ckfinder/ckfinder.html';
$CKeditor->config['filebrowserImageBrowseUrl'] = 'browser/browser.php?type=Images';
$CKeditor->config['filebrowserFlashBrowseUrl'] = 'ckfinder/ckfinder.html?type=Flash';
$CKeditor->config['filebrowserUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files';
$CKeditor->config['filebrowserImageUploadUrl'] = 'uploader/uploader.php?type=Images';
$CKeditor->config['filebrowserFlashUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash';
$CKeditor->editor('page_desc','**page_desc**');
For display content I use
<?php echo stripslashes($details[0]["page_desc"]); ?>
I wanted to display on the place of Page_desc(last Line of Code). How to do that?
You can simply download the ckeditor package and do this simple 2 step
Step 1 : Include the ckeditor.js from your file
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
Step 2 : Include the class name as ckeditor to your textarea
Then you can see the ckeditor with simple step
Note : Make sure the ckeditor.js is in the proper path
Hope this helps you

TeeChart for PHP : Differences between image render and JavaScript Export

I try to use the right axis of TeeChart for PHP. I'm aware that we need to link a valid serie to both vertical axis. In fact, I have tried a simple test with the custom axis demo on the Steema site. I cut and pasted the demo and try to export it to javascript instead of rendering it.
I used this code to export to javascript :
echo $tChart1->getChart()->getExport()->getImage()->getJavaScript()->Render()->toString();
Here is a snapshot of the 2 renders side-by-side (sorry to put it in a link, this forum don't allow me to post pictures yet...)
Is there a way to get the right axis to show with the export?
EDIT:
Here is the code to test on your side :
<?php
//Includes
include "../../../sources/TChart.php";
$chart1 = new TChart(600,450);
$chart1->getChart()->getHeader()->setText("Custom Axes Demo");
$chart1->getAspect()->setView3D(false);
$line1 = new Line($chart1->getChart());
$line2 = new Line($chart1->getChart());
$line1->setColor(Color::RED());
$line2->setColor(Color::GREEN());
$chart1->addSeries($line1);
$chart1->addSeries($line2);
// Speed optimization
$chart1->getChart()->setAutoRepaint(false);
for($t = 0; $t <= 10; ++$t) {
$line1->addXY($t, (10 + $t), Color::RED());
if($t > 1) {
$line2->addXY($t, $t, Color::GREEN());
}
}
$chart1->getAxes()->getLeft()->setStartPosition(0);
$chart1->getAxes()->getLeft()->setEndPosition(50);
$chart1->getAxes()->getLeft()->getAxisPen()->color = Color::RED();
$chart1->getAxes()->getLeft()->getTitle()->getFont()->setColor(Color::RED());
$chart1->getAxes()->getLeft()->getTitle()->getFont()->setBold(true);
$chart1->getAxes()->getLeft()->getTitle()->setText("1st Left Axis");
$chart1->getAxes()->getTop()->getLabels()->setAngle(45);
$chart1->getAxes()->getTop()->getTitle()->getFont()->setColor(Color::YELLOW());
$chart1->getAxes()->getTop()->getTitle()->getFont()->setBold(true);
$chart1->getAxes()->getBottom()->getLabels()->setAngle(0);
$chart1->getAxes()->getRight()->getLabels()->setAngle(45);
$chart1->getAxes()->getBottom()->getTitle()->getFont()->setColor(new Color(255,25,25));
$chart1->getAxes()->getBottom()->getTitle()->getFont()->setBold(true);
$chart1->getAxes()->getRight()->getTitle()->getFont()->setColor(Color::BLUE());
$chart1->getAxes()->getRight()->getTitle()->getFont()->setBold(true);
$chart1->getAxes()->getRight()->getTitle()->setText("OtherSide Axis");
$chart1->getAxes()->getRight()->getLabels()->getFont()->setColor(Color::BLUE());
$chart1->getAxes()->getRight()->getAxisPen()->setColor(Color::BLUE());
$chart1->getAxes()->getTop()->getTitle()->setText("Top Axis");
$chart1->getAxes()->getBottom()->getTitle()->setText("Bottom Axis");
$line1->setHorizontalAxis(HorizontalAxis::$BOTH);
$line1->setVerticalAxis(VerticalAxis::$BOTH);
$axis1 = new Axis(false, false, $chart1->getChart());
$chart1->getAxes()->getCustom()->add($axis1);
$line2->setCustomVertAxis($axis1);
$axis1->setStartPosition(50);
$axis1->setEndPosition(100);
$axis1->getTitle()->getFont()->setColor(Color::GREEN());
$axis1->getTitle()->getFont()->setBold(true);
$axis1->getTitle()->setText("Extra Axis");
$axis1->getTitle()->setAngle(90);
$axis1->setRelativePosition(20);
$axis1->getAxisPen()->setColor(Color::GREEN());
$axis1->getGrid()->setVisible(false);
echo $tChart1->getChart()->getExport()->getImage()->getJavaScript()->Render()->toString();?>
I've modified the end of your test page to show both the HTML5 and the PHP charts at the same page:
echo $chart1->getChart()->getExport()->getImage()->getJavaScript()->Render()->toString();
$chart1->render("chart1.png");
$rand=rand();
print '<img src="chart1.png?rand='.$rand.'">';
Then, I've modified TeeChart PHP sources to also export the custom axes and the assign.
It now looks like this:
Please, send a mail to "info#steema.com" and we'll send you the modified unit (JavaScriptExport.php).

how to put jpgraph into PDF using dompdf-0.5.1

It took me 12 hours still no improvement. I try displaying different images from my computer stored in the server and the result was successful. however when displaying the reports pie graph, it wont read every time the system tries to convert to pdf. It gives a blank pdf file. On the other hand, I can view the pie graph I created by using echo''; in the reports.php. I used the same concept in dompdf file but its not working.
DOMPDF
<html>
<head>
<title></title>
</head>
<body>
<?php echo'<img src="reports-display.php"/>';?>
</body>
</html>
<?php
$html = ob_get_clean();
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf");
?>
JPGRAPH Drawing
<?php
require('dbcon.php');
require_once('jpgraph/src/jpgraph.php');
require_once ('jpgraph/src/jpgraph_pie.php');
require_once ('jpgraph/src/jpgraph_pie3d.php');
//LEGEND
//YELLOW=LIVE BLUE=WAITING GREEN=DONE
//sql query for live
$live = mysql_query("Select count(*) as count1 from tbl_display_ads where status LIKE '%Live%'") or die(mysql_error());
//sql query for waiting
$waiting = mysql_query("Select count(*) as count2 from tbl_display_ads where status LIKE '%Waiting%'") or die(mysql_error());
//sql query for done/posted advertisement
$done = mysql_query("Select count(*) as count3 from tbl_display_ads where status LIKE '%Done%'") or die(mysql_error());
//While loop for live
while($resultlive = mysql_fetch_array($live))
{
$totallive = $resultlive['count1'];
}
//While loop for waiting
while($resultwaiting = mysql_fetch_array($waiting))
{
$totalwaiting = $resultwaiting['count2'];
}
//While loop for done
while($resultdone = mysql_fetch_array($done))
{
$totaldone = $resultdone['count3'];
}
// Some data
$data = array($totallive,$totalwaiting,$totaldone);
// Create the Pie Graph.
$graph = new PieGraph(500,450);
$theme_class= new VividTheme;
$graph->SetTheme($theme_class);
// Set A title for the plot
$graph->title->Set("Figure 1.1: Totality of Display Advertisement");
// Create
$p1 = new PiePlot3D($data);
$p1->SetCenter(0.5,0.55);
$p1->SetLegends(array("Live","Waiting","Done"));
$graph->legend->SetPos(0.5,0.100,'center','bottom');
$graph->Add($p1);
$p1->ShowBorder();
$p1->SetColor('black');
$p1->ExplodeSlice(1);
$graph->Stroke();
// Get the handler to prevent the library from sending the
// image to the browser
$gdImgHandler = $graph->Stroke(_IMG_HANDLER);
// Stroke image to a file and browser
// Default is PNG so use ".png" as suffix
$fileName = "/tmp/imagefile.png";
$graph->img->Stream($fileName);
// Send it back to browser
$graph->img->Headers();
$graph->img->Stream();
?>
I finally found out the solution. in the report-display.php I set the extension name of the graph to .png and save to the directory folder for reports.
DEFINE("DEFAULT_GFORMAT","auto");
$graph->img->SetImgFormat("png");
if(file_exists("Reports/reports-display.png")) unlink("Reports/reports-display.png");
$graph->Stroke("Reports/reports-display.png");
The problem is that you're essentially asking dompdf to grab an image file called "reports-display.php" from the local filesystem. When you use $dompdf->load_html() dompdf has no idea where the content arrives from. Any resource references in the HTML that lack a full URL are pulled in via the local filesystem. Since dompdf does not parse the PHP the source will be read in, which is obviously not a valid image document.
You're found a valid solution in saving the file locally. There are two other possibilities:
1) Point to the jpgraph script through your web server.
<html>
<head>
<title></title>
</head>
<body>
<img src="http://example.com/reports-display.php"/>
</body>
</html>
2) Capture the jpgraph output and insert into the document as a data-uri.
<html>
<head>
<title></title>
</head>
<body>
<img src="data:image/png;base64,<?php echo base64_encode(include_once('reports-display.php');?>"/>
</body>
</html>
With this method reports-deplay.php would have to be updated to return the image rather than stream it. Something like:
$graph = new PieGraph(500,450);
// snip steps that generate the content
return $graph->Stroke();

code to expand excel column width in php while exporting

I am new to PHP and trying to export some DB data to Excel file as below. But in the output I want the column widths to be adjusted automatically to view the entire content. See the code I am using to export data. I am not using any third party libraries for export.
<?php
require_once("db.php");
$contents="email,time_in,v_id,time_out\n";
$user_query = mysql_query('SELECT * FROM table');
while($row = mysql_fetch_array($user_query))
{
$contents.=$row['email'].",";
$contents.=$row['time_in'].",";
$contents.=$row['v_id'].",";
$contents.=$row['time_out']."\n";
}
// remove html and php tags etc.
$contents = strip_tags($contents);
//header to make force download the file
header("Content-Disposition: attachment; filename=Report".date('d-m-Y').".xls");
print $contents;
?>
Is there any way to format the output ?

Error occurs while importing excel file into MYSQL in php

I am new to php. I need to import excel details into MySQL database in php. I downloaded 2 files reader.php & oleread.php and save that under wamp/www/folder. When I execute the following code, the server throw a error like
The filename samp.xls is not readable
Give the solution to recover this problem. my code is:
<html>
<head>
<title>Save Excel file details to the database</title>
</head>
<body>
<?php
include 'db_connection.php';
include 'reader.php';
$excel = new Spreadsheet_Excel_Reader();
?>
<table border="1">
<?php
$excel->read('samp.xls');
$x=2;
while($x<=$excel->sheets[0]['numRows']) {
$id = isset($excel->sheets[0]['cells'][$x][1]) ? $excel->sheets[0]['cells'][$x][1] : '';
$name = isset($excel->sheets[0]['cells'][$x][2]) ? $excel->sheets[0]['cells'][$x][2] : '';
// Save details
$sql_insert="INSERT INTO students (sid,name) VALUES ('$id','$name')";
$result_insert = mysql_query($sql_insert) or die(mysql_error());
$x++;
}
?>
</table>
</body>
</html>
The filename samp.xls is not readable
First thing to come to mind is that your php server cannot read your excel file ..
WAMP is on Windows, so Right-Click your excel file, and add read property to Everyone
why not import it directly into phpmyadmin?? click here

Categories