$arrData = array("chart" => array("caption" => "Cereal Crop Index", "paletteColors" => "#0075c2", "bgColor" => "#ffffff", "borderAlpha" => "20", "canvasBorderAlpha" => "0", "usePlotGradientColor" => "0", "plotBorderAlpha" => "10", "showXAxisLine" => "1", "xAxisLineColor" => "#999999", "showValues" => "0", "divlineColor" => "#999999", "divLineIsDashed" => "1", "showAlternateHGridColor" => "0")); $arrData["data"] = array(); // Push the data into the array while ($row = mysqli_fetch_array($result)) { array_push($arrData["data"], array("label" => $row["district_name"], "value" => $row["cerial_index"])); } /*JSON Encode the data to retrieve the string containing the JSON representation of the data in the array. */ $jsonEncodedData = json_encode($arrData); /*Create an object for the column chart using the FusionCharts PHP class constructor. Syntax for the constructor is ` FusionCharts("type of chart", "unique chart id", width of the chart, height of the chart, "div id to render the chart", "data format", "data source")`. Because we are using JSON data to render the chart, the data format will be `json`. The variable `$jsonEncodeData` holds all the JSON data for the chart, and will be passed as the value for the data source parameter of the constructor.*/ $columnChart1 = new FusionCharts("Column3D", "myFirstChart1", 1000, 500, "chart-1", "json", $jsonEncodedData); $columnChart2 = new FusionCharts("Pie3D", "myFirstChart2", 1000, 500, "chart-2", "json", $jsonEncodedData); $columnChart3 = new FusionCharts("line", "myFirstChart3", 1000, 500, "chart-3", "json", $jsonEncodedData); $columnChart4 = new FusionCharts("area2D", "myFirstChart4", 1000, 500, "chart-4", "json", $jsonEncodedData); // Render the chart $columnChart1->render(); $columnChart2->render(); $columnChart3->render(); $columnChart4->render(); // Close the database connection $dbhandle->close(); } ?> <div id="chart-1"><!-- Fusion Charts will render here--></div> <div id="chart-2"><!-- Fusion Charts will render here--></div> <div id="chart-3"><!-- Fusion Charts will render here--></div> <div id="chart-4"><!-- Fusion Charts will render here--></div> </body> </html>
// If the query returns a valid response, prepare the JSON string if ($result) { // The `$arrData` array holds the chart attributes and data $arrData = array("chart" => array("caption" => "Jumlah Gangguan Penyulang > 5 menit Per Area Unit", "bgColor" => "#ffffff", "borderAlpha" => "20", "canvasBorderAlpha" => "0", "usePlotGradientColor" => "0", "plotBorderAlpha" => "10", "showXAxisLine" => "1", "xAxisLineColor" => "#999999", "showValues" => "0", "divlineColor" => "#999999", "divLineIsDashed" => "1", "showAlternateHGridColor" => "0")); $arrData["data"] = array(); // Push the data into the array while ($row = $result->fetch()) { $GANGGUANTOTAL = @($row["BESAR5"] + $row["KECIL5"]) / $row["PANJANG"]; array_push($arrData["data"], array("label" => $row["AREA"], "value" => $GANGGUANTOTAL)); } /*JSON Encode the data to retrieve the string containing the JSON representation of the data in the array. */ $jsonEncodedData = json_encode($arrData); /*Create an object for the column chart using the FusionCharts PHP class constructor. Syntax for the constructor is ` FusionCharts("type of chart", "unique chart id", width of the chart, height of the chart, "div id to render the chart", "data format", "data source")`. Because we are using JSON data to render the chart, the data format will be `json`. The variable `$jsonEncodeData` holds all the JSON data for the chart, and will be passed as the value for the data source parameter of the constructor.*/ $columnChart = new FusionCharts("column2D", "myFirstChart", 700, 350, "chartContainer", "json", $jsonEncodedData); // Render the chart $columnChart->render(); // Close the database connection $conn = null; } ?> <title> Rekapitulasi Laporan Gangguan Penyulang</title> <div class="content-wrapper"> <!-- Content Header (Page header) --> <section class="content-header"> <h1> Rekapitulasi Laporan <small>Gangguan Penyulang</small> </h1> <ol class="breadcrumb">
<!-- FusionCharts core package JS files --> <script src="http://static.fusioncharts.com/code/latest/fusioncharts.js"></script> <script src="http://static.fusioncharts.com/code/latest/fusioncharts.charts.js"></script> <script src="http://static.fusioncharts.com/code/latest/themes/fusioncharts.theme.fint.js"></script> </head> <body> <?php pg_query($dbconn, "SELECT DISTINCT browser, shareval FROM browsershare; "); $result = pg_query($dbconn, "SELECT DISTINCT browser, shareval FROM browsershare; ") or exit("Error with quering database"); if ($result) { // creating an associative array to store the chart attributes $arrData = array("chart" => array("theme" => "fint", "caption" => "Browser Market Share", "subcaption" => "February 2016", "captionFontSize" => "24", "paletteColors" => "#A2A5FC, #41CBE3, #EEDA54, #BB423F #,F35685", "baseFont" => "Quicksand, sans-serif", "baseFontColor" => "#FFFFFF", "baseFontSize" => "14", "numberSuffix" => "%", "showBorder" => "0", "startingAngle" => "0", "showPercentValues" => "0", "showPercentInTooltip" => "0", "decimals" => "1", "labelFontColor" => "#FFFFFF", "labelFontSize" => "14", "bgColor" => "#50585F", "bgAlpha" => "100", "doughnutRadius" => "50", "enableSmartLabels" => "1", "smartLineColor" => "#FCFDFD", "smartLineThickness" => "1", "showLegend" => "1", "legendBorderAlpha" => '0', "legendShadow" => '0', "legendItemFontSize" => '10', "legendItemFontColor" => "#FFFFFF", "toolTipBgColor" => "#000000", "toolTipBgAlpha" => "70", "toolTipPadding" => "10", "toolTipBorderColor" => "#FFFFFF", "toolTipBorderThickness" => "1", "toolTipBorderRadius" => "2")); $arrData["data"] = array(); // iterating over each data and pushing it into $arrData array while ($row = pg_fetch_array($result)) { array_push($arrData["data"], array("label" => $row["browser"], "value" => $row["shareval"])); } $jsonEncodedData = json_encode($arrData); // creating FusionCharts instance $doughnutChart = new FusionCharts("doughnut2d", "browserShareChart", '100%', 450, "doughnut-chart", "json", $jsonEncodedData); // FusionCharts render method $doughnutChart->render(); // closing database connection pg_close($dbconn); } ?> <!-- creating chart container --> <div id="doughnut-chart">A beautiful donut chart is on its way!</div> </body> </html>
$end = $_POST["end"]; if (strtotime($end) < strtotime($start)) { echo "Tanggal tidak valid"; } else { $per_periode = "SELECT nama_barang, sum(n_pakai) as 'jumlah pemakaian' FROM t_pemakaian WHERE tanggal<='" . $end . "' and tanggal>='" . $start . "' GROUP BY kode_barang"; $result = $conn->query($per_periode); echo "<br>"; if ($result->num_rows > 0) { include "fusioncharts.php"; $arrData = array("chart" => array("caption" => "Pemakaian ATK dari periode " . $start . " sampai " . $end, "xAxisName" => "Nama Barang", "yAxisName" => "Jumlah Pemakaian (pcs)")); $arrData["data"] = array(); while ($row = mysqli_fetch_array($result)) { array_push($arrData["data"], array("label" => $row["nama_barang"], "value" => $row["jumlah pemakaian"])); } $chart = new FusionCharts("column2D", "periodChart", 600, 400, "chart-1", "json", json_encode($arrData)); $chart->render(); ?> <div id="chart-1"></div> <?php } else { echo "tidak ada hasil"; } } } } } } $conn->close(); ?> </div> </div>
$colorrange = $chart->addChild('colorrange'); $dials = $chart->addChild('dials'); foreach ($arrData as $key => $value) { $chart->addAttribute($key, $value); } // fetching data from database $query = "SELECT * FROM `angular_data`"; $query_run = mysqli_query($con, $query); while ($query_row = mysqli_fetch_assoc($query_run)) { $minvalue = $query_row['minvalue']; $maxvalue = $query_row['maxvalue']; $code = $query_row['code']; $value = $query_row['value']; $color = $colorrange->addChild('color'); $color->addAttribute('minvalue', "{$minvalue}"); $color->addAttribute('maxvalue', "{$maxvalue}"); $color->addAttribute('code', "{$code}"); $dial = $dials->addChild('dial'); $dial->addAttribute('value', "{$value}"); } $xml_data = $xml->asXML(); // minifying the xml code $xml_data = preg_replace("/\r\n|\r|\n|\\<[\\?\\/]{0,1}xml[^>]*>/", '', $xml_data); // creaing chart objecy $angulargauge = new FusionCharts("angulargauge", "myFirstChart", 600, 300, "chart-1", "xml", $xml_data); // calling render method to render the chart $angulargauge->render(); ?> <div id="chart-1">Fusion Charts will render here</div> </body> </html>
//set expenses data for each day in array $expenses_data_7_days = mysqli_fetch_array($get_7_days_expenses, MYSQLI_ASSOC); $expenses = $expenses_data_7_days['total_buy']; array_push($days_list, $dates); //revert both arrays to get results in ascending order array_push($sales_list, $sales); array_push($expenses_list, $expenses); array_push($arrData['data'], array("label" => (string) $days_list[$index], "value" => (string) $sales_list[$index])); array_push($arrData2['data'], array("label" => (string) $days_list[$index], "value" => (string) $expenses_list[$index])); } $jsonEncodedData = json_encode($arrData); $jsonEncodedData2 = json_encode($arrData2); $columnChart = new FusionCharts("column2d", "sales", 1000, 300, "chart-1", "json", $jsonEncodedData); $columnChart2 = new FusionCharts("column2d", "expenses", 1000, 300, "chart-2", "json", $jsonEncodedData2); $columnChart->render(); $columnChart2->render(); $content->drawNav($accountBalance, $networth, $sellOrders, $escrow, $username, $character_get, $getCharacterList); ?> <div id="page-wrapper"> <?php $content->drawHeader($getCharacterPortrait, $characterName, "Statistics"); ?> <div class="row"> <?php $content->columns_def(); ?> <head> <title>Statistics</title> <!-- Bootstrap Core CSS --> <link href="../bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"> <!-- MetisMenu CSS -->
public function makeChart($type, $chartId, $width, $height, $divId, $typeOfData, $actualData) { $columnChart = new FusionCharts("Column2D", "myFirstChart", 600, 300, "chart-1", "json", $actualData); $columnChart->render(); }
$strQuery = "SELECT DISTINCT month, year_a, year_b FROM visitor_data; "; $result = $dbhandle->query($strQuery) or exit("Error code ({$dbhandle->errno}): {$dbhandle->error}"); if ($result) { $arrData = array("chart" => array("caption" => "Comparison of Yearly Visitors", "xAxisname" => "Month", "yAxisName" => "Revenues (In USD)", "numberPrefix" => "\$", "plotFillAlpha" => "80", "showValues" => "1", "placeValuesInside" => "1", "usePlotGradientColor" => "0", "rotateValues" => "1", "valueFontColor" => "#FFFFFF", "showHoverEffect" => "1", "rotateValues" => "1", "showXAxisLine" => "1", "xAxisLineThickness" => "1", "xAxisLineColor" => "#999999", "showAlternateHGridColor" => "0", "legendBgAlpha" => "0", "legendBorderAlpha" => "0", "legendShadow" => "0", "legendItemFontSize" => "10", "legendItemFontColor" => "#666666", "theme" => "fint")); // creating array for categories object $categoryArray = array(); $dataseries1 = array(); $dataseries2 = array(); // pushing category array values while ($row = mysqli_fetch_array($result)) { array_push($categoryArray, array("label" => $row["month"])); array_push($dataseries1, array("value" => $row["year_a"])); array_push($dataseries2, array("value" => $row["year_b"])); } $arrData["categories"] = array(array("category" => $categoryArray)); // creating dataset object $arrData["dataset"] = array(array("seriesName" => "2014", "data" => $dataseries1), array("seriesName" => "2015", "data" => $dataseries2)); $jsonEncodedData = json_encode($arrData); // chart object $msChart = new FusionCharts("mscolumn2d", "chart1", "100%", "400", "chart-container", "json", $jsonEncodedData); $msChart->render(); // closing db connection $dbhandle->close(); } ?> <center> <div id="chart-container">Chart will render here!</div></center> </body> </html>
$dbhandle = new mysqli($hostdb, $userdb, $passdb, $namedb); if ($dbhandle->connect_error) { exit("There was an error with your connection: " . $dbhandle->connect_error); } ?> <html> <head> <title>Creating Interactive Charts using PHP and MySQL</title> <script src="/path/to/fusioncharts.js"></script> </head> <body> <?php $strQuery = "SELECT DISTINCT search_engine, search_percentage FROM pyramid_data; "; $result = $dbhandle->query($strQuery) or exit("Error code ({$dbhandle->errno}): {$dbhandle->error}"); if ($result) { $arrData = array("chart" => array("theme" => "fint", "caption" => "Top 5 Search Engines (By Percentage)", "paletteColors" => "#0075c2,#1aaf5d,#f2c500,#f45b00,#8e0000", "bgColor" => "#ffffff", "showBorder" => "0", "use3DLighting" => "0", "showShadow" => "0", "enableSmartLabels" => "0", "startingAngle" => "0", "showPercentValues" => "1", "showPercentInTooltip" => "0", "decimals" => "1", "captionFontSize" => "14", "subcaptionFontSize" => "14", "subcaptionFontBold" => "0", "toolTipColor" => "#ffffff", "toolTipBorderThickness" => "0", "toolTipBgColor" => "#000000", "toolTipBgAlpha" => "80", "toolTipBorderRadius" => "2", "toolTipPadding" => "5", "showHoverEffect" => "1", "showLegend" => "1", "legendBgColor" => "#ffffff", "legendBorderAlpha" => '0', "legendShadow" => '0', "legendItemFontSize" => '10', "pieRadius" => "139", "legendItemFontColor" => '#666666')); $arrData["data"] = array(); while ($row = mysqli_fetch_array($result)) { array_push($arrData["data"], array("label" => $row["search_engine"], "value" => $row["search_percentage"])); } $jsonEncodedData = json_encode($arrData); $pieChart = new FusionCharts("pie3d", "myFirstChart", 500, 350, "chart-container", "json", $jsonEncodedData); $pieChart->render(); $dbhandle->close(); } ?> <center> <div id="chart-container">Awesome Chart on its way!</div></center> </body> </html>