PHP code example of zingchart / php_wrapper
1. Go to this page and download the library: Download zingchart/php_wrapper library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zingchart / php_wrapper example snippets
use ZingChart\PHPWrapper\ZC;
$datay = array();
$a = 6.619;
$b = 0.113;
$index = 0;
for ($x = 50; $x < 600; $x += 50, $index++) {
array_push($datay, $a + $b*$x);
}
$zc = new ZC("myChart");
$zc->setChartType("line");
$zc->setTitle("PHP 5.6 render");
$zc->setSeriesData(0, $datay);
$zc->setChartHeight("400px");
$zc->setChartWidth("100%");
$zc->render();
$zc = new ZC("myChart");
$zc->connect($host,$port,$uName,$pswd,$db);
$data = $zc->query($mySqlQuery, true);
$zc->setSeriesData($data[1]);
$zc->render();
$zc->closeConnection();
$zc = new ZC("myChart");
$zc->setSeriesData([1,4,2,6,3]);
$zc->render();
$zc = new ZC("chartDiv");
$zc = new ZC("chartDiv", "line");
$zc = new ZC("chartDiv", "line", "dark");
$zc = new ZC("chartDiv", "line", "dark", "600");
$zc = new ZC("chartDiv", "line", "dark", "600", "400");
$zc = new ZC("chartDiv", null, "dark");
$zc = new ZC("chartDiv", "bar", null, 600, 400);
$zc->render();
$chart1Script = $zc->getRenderScript();// This stores the script, to be printed later
echo $chart1Script;// This will render the chart
$zc->connect("127.0.0.1","8889","root","root","mydb");
$zc->closeConnection();
$queryStr = "SELECT timestamp, unitsSold, expected, anotherMetric FROM feed_data";
$zc->query($queryStr, true);
$queryStr = "SELECT unitsSold, expected, anotherMetric FROM feed_data";
$zc->query($queryStr, false);
$fieldNames = $zc->getFieldNames();
$zc->setTitle("Sandwiches Consumed");
$zc->setSubtitle("March 1 thru March 31, 2016");
$zc->setLegendTitle("Sandwich Types");
$zc->setScaleXTitle("Quantity");
$zc->setScaleYTitle("Date");
$zc->setScaleXLabels(array("Mar 1", "Mar 2", "Mar 3));
$zc->setScaleYLabels(array("0:10:100");
$zc->setSeriesData(0, [5,7,11]);
$zc->setSeriesData([[3,7,1], [20,32,37], [1,25,48]]);
$zc->setSeriesText(["BLT","Tuna","Club"]); // applies "BLT" to series[0], "Tuna" to series[1],..
$zc->setSeriesText(0, "BLT"); // applies "BLT" to series[0]
$zc->setChartType("line");
$zc->setChartWidth("600"); // in pixels
$zc->setChartWidth("100%");
$zc->setChartHeight("400"); // in pixels
$zc->setChartHeight("50%");
$zc->setChartTheme("dark");
$zc->setFullscreen();
$zc->enableScaleXZooming();
$zc->enableScaleYZooming();
$zc->enableCrosshairX();
$zc->enableCrosshairY();
$zc->enableTooltip();
$zc->enableValueBox();
$zc->enablePreview();
$zc->disableScaleXZooming();
$zc->disableScaleYZooming();
$zc->disableCrosshairX();
$zc->disableCrosshairY();
$zc->disableTooltip();
$zc->disableValueBox();
$zc->disablePreview();
$chartTitle = $zc->getTitle();
$chartSubtitle = $zc->getSubtitle();
$legendTitle = $zc->getLegendTitle();
$config = $zc->getConfig();
$xAxisTitle = $zc->getScaleXTitle();
$yAxisTitle = $zc->getScaleYTitle();
$xAxisLabels = $zc->getScaleXLabels();
$yAxisLabels = $zc->getScaleYLabels();
$plotValues = $zc->getSeriesData();
$plotSeriesText = $zc->getSeriesText();
$zc->setConfig("legend.header.background-color", "red");
$zc->setConfig("series[1].values", array(5,9,13,10,22,39));
$legendConfig = array(
"header" => array(
"background-color" => "red"
),
"marker" => array(
"border-color" => "orange",
"border-width" => "3px",
"shadow-angle" => "115"
)
);
$zc->setConfig("legend", $legendConfig);
$myConfig = array(
"legend" => array(
"header" => array(
"background-color" => "red"
),
"marker" => array(
"border-color" => "orange",
"border-width" => "3px",
"shadow-angle" => "115"
)
),
"series" => array(
array(
"values" => array(33,45,27,32,15),
"text" => "Apples"
),
array(
"values" => array(1,5,9,3,7),
"text" => "Oranges"
)
)
);
$zc->trapdoor(json_encode($myConfig));
$jsonString = <<< EOT
{
"legend":{
"header":{
"background-color":"red"
},
"marker":{
"border-color":"orange",
"border-width":"3px",
"shadow-angle":"115"
}
},
"series":[
{
"values":[33,45,27,32,15],
"text":"Apples"
},
{
"values":[1,5,9,3,7],
"text":"Oranges"
}]
}
EOT;
$zc->trapdoor($jsonString);
$zc = new ZC("myChart", "area", "light", 600, 400);
$zc->trapdoor(json_encode($myConfig));
$zc->render();