First of all, I'm very new to C# and Json.

首先,我对C#和Json很新。

I wanted to plot a graph from mysql table data in a C# GUI. I made a PHP file to select the data from mysql database table and echoed the selected contents in json array using echo json_encode(array("result"=>$result))

我想在C#GUI中绘制mysql表数据的图形。我创建了一个PHP文件来从mysql数据库表中选择数据,并使用echo json_encode(array(“result”=> $ result))在json数组中回显所选内容

here is my PHP:

这是我的PHP:

<?php
define('HOST','*********************');
define('USER','*********************');
define('PASS','*********************');
define('DB','***********************');

if($_SERVER['REQUEST_METHOD']=='GET'){

 $start = $_GET['start'];
 $ending  = $_GET['ending'];
}

$con = mysqli_connect(HOST,USER,PASS,DB);


$sql = "SELECT * FROM table WHERE date_time BETWEEN '$start' and '$ending'" ;
$res = mysqli_query($con,$sql);

$result = array();
while($row = mysqli_fetch_array($res)){
array_push($result,array('id'=>$row[0],'p_pairs'=>$row[1],'temp1'=>$row[2]  ,'temp2'=>$row[3],'temp3'=>$row[4],'temp4'=>$row[5],'temp5'=>$row[6],'avg_current'=>$row[7],'avg_voltage'=>$row[8],'kw'=>$row[9],'kwh'=>$row[10]));
}

echo json_encode(array($result));

mysqli_close($con);

?>

using the link, I can see the json array clearly between the datetime gap.All I wanted is to plot the graph of temperature values (temp1, temp2,..), p-pairs values and others with the date_time in a line graph to read the historical data.

使用链接,我可以清楚地看到日期时间间隙之间的json数组。我想要的是用线图中的date_time绘制温度值(temp1,temp2,..),p对值等的图形。阅读历史数据。

All I get when I access the PHP page is:

我访问PHP页面时得到的是:

[[{"id":"1","p_pairs":"0000-00-00 00:00:00","temp1":"2","temp2":"100","temp3":"100","temp4":"100","temp5":"100","avg_current":"100","avg_voltage":"300","kw":"300","kwh":"300"},{"id":"2","p_pairs":"0000-00-00 00:00:00","temp1":"45","temp2":"105","temp3":"230","temp4":"100","temp5":"2500","avg_current":"570","avg_voltage":"100","kw":"250","kwh":"1000"},{"id":"3","p_pairs":"2016-01-07 21:10:00","temp1":"45","temp2":"105","temp3":"230","temp4":"100","temp5":"2500","avg_current":"570","avg_voltage":"100","kw":"250","kwh":"1000"},{"id":"4","p_pairs":"2016-01-07 21:10:00","temp1":"45","temp2":"105","temp3":"230","temp4":"100","temp5":"2500","avg_current":"570","avg_voltage":"100","kw":"250","kwh":"1000"}]]

NOTE: some datetime is set as default here. I just wanted to show this array. The correct one will be perfect to plot the graph.

注意:某些日期时间在此处设置为默认值。我只想展示这个数组。正确的一个将是完美的绘制图形。

I can can take these array in a string using a web request from C#. using the bellow code:

我可以使用来自C#的Web请求将这些数组放在一个字符串中。使用下面的代码:

        System.Net.WebClient wc = new System.Net.WebClient();
        byte[] raw = wc.DownloadData("url to php");

        string webData = System.Text.Encoding.UTF8.GetString(raw);

It'll be a big help If someone can help me to plot this in a line graph as date_time Vs temp1, temp2 or p_pairs and like that in C# GUI...

这将是一个很大的帮助如果有人可以帮我在线图中将其绘制为date_time Vs temp1,temp2或p_pairs,就像在C#GUI中那样...

This is going to be a big help for me. Thanking you in advance.

这对我来说将是一个很大的帮助。提前感谢你。

1 个解决方案

#1


1

Firstly get a class to work from. You can dynamically create a class from Json

首先要上课。您可以从Json动态创建一个类

If you are happy to have a dependency upon the System.Web.Helpers assembly, then you can use the Json class:

如果您很高兴依赖System.Web.Helpers程序集,那么您可以使用Json类:

dynamic data = Json.Decode(json);

It is included with the MVC framework as an additional download to the .NET 4 framework. Or use the NewtonSoft one.

它包含在MVC框架中,作为.NET 4框架的附加下载。或者使用NewtonSoft。

Next get a chart component: https://msdn.microsoft.com/en-us/library/dd489237.aspx and bind your data to the chart

接下来得到一个图表组件:https://msdn.microsoft.com/en-us/library/dd489237.aspx并将您的数据绑定到图表

更多相关文章

  1. Navicat 图形化操作mysql 基本操作
  2. ubuntu 14.04中安装phpmyadmin即mysql图形管理界面
  3. javascript判断数组和对象中是否存在某元素
  4. [JavaScript] 将字符串数组转化为整型数组
  5. 数组中的值由于未知原因而更改
  6. javascript 动态数组的使用
  7. 如何使用变量创建数组?
  8. 超全超实用的Javascript类库和jQuery插件大全之一:图片,地图和图形
  9. 推json敲出可观察的数组

随机推荐

  1. ViewPager的滑动禁止和滑动启动
  2. android发送通知及更新通知
  3. PacketReader 如何实现smack数据监听机制
  4. 第一个Android程序
  5. android中Appwidget的使用
  6. 在谷歌中映射V2…fragment.getMap()返回n
  7. 不同Android版本设备正确获取屏幕分辨率
  8. Android开发——联系人中几种常见的mimet
  9. android surfaceview里onTouchEvent 画图
  10. 绑定服务后台播放音频的简单示例