[英]how to read json file into a php array and plot a graph by using this array?
i am able to read a json file into an array and display the output but i want to use that array directly to give it as a input to another php function to plot a graph, 我能够将json文件读入数组并显示输出,但是我想直接使用该数组将其作为另一个php函数的输入来绘制图形,
how to read json file into a php array and plot a graph by using this array ? 如何将json文件读入php数组并使用此数组绘制图形?
<?php
$string = file_get_contents("json.json");
$example_data=json_decode($string,true);
foreach ($example_data as $k => $v) {
echo $k, ' : ', $v;
}
?>
but instead of displaying it as an output text, i want to give this example_data as an input array to another php function, 但我不想将其显示为输出文本,而是希望将此example_data作为输入数组提供给另一个php函数,
in the above code, instead of declaring the example_data, i want to read it from another json file as i did in the first code, can anyone give me a solution to this ? 在上面的代码中,而不是声明example_data,我希望像在第一个代码中一样从另一个json文件中读取它,有人可以给我解决方案吗?
It looks as though all you need to do is: 您似乎所需要做的只是:
$string = file_get_contents("json.json");
$example_data=json_decode($string,true);
$plot = new PHPlot();
$plot->SetDataValues($example_data);
Unless you JSON file is structured differently to that of the example. 除非您的JSON文件的结构与示例的结构不同。
You probably need to code: 您可能需要编写以下代码:
<?php
//Include the code
require_once 'C:/xampp/htdocs/formattool/phplot-6.1.0/phplot.php';
//Define the object
$plot = new PHPlot();
$string = file_get_contents("json.json");
$example_data=json_decode($string,true);
$plot->SetDataValues($example_data);
//Turn off X axis ticks and labels because they get in the way:
$plot->SetXTickLabelPos('none');
$plot->SetXTickPos('none');
//Draw it
$plot->DrawGraph();
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.