如何在C#中创建显示查询结果的图表? [英] How can I make a chart in C# that shows my query results?
本文介绍了如何在C#中创建显示查询结果的图表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好。我使用PgAdmin 4作为数据库,以便将一些查询结果放入图表中。为了做到这一点,我几乎找不到很好的代码示例。有没有人可以帮我或者介绍一个很好的资源?我是编程的新手,所以我的代码可能看起来不太好或不专业。请HELPPPP
我尝试过:
使用系统;
使用 Npgsql;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;
命名空间 DBConnectExperiment
{
class 程序
{
静态 void Main( string [] args)
{
string query = 选择计数(fietsdiefstal.buurt),climat.tn来自fietsdiefstal内部连接气候fietsdiefstal.year = climat.year group by(fietsdiefstal.buurt), climat.tn;
string ip = 127.0.0.1\" 跨度>;
string port = 5432跨度>;
string database = project3跨度>;
string username = project3跨度>;
string password = project3跨度>;
string deliminator = ;跨度>;
string connectionParameter = String .Format( Server = + ip + deliminator + Port = + port + deliminator + User Id = + username + deliminator + Password = + password + deliminator + Database = + database);
try
{
NpgsqlConnection conn = new NpgsqlConnection(connectionParameter) ;
Console.WriteLine( 已建立连接);
conn.Open();
Console.WriteLine( 数据库已打开...);
NpgsqlCommand queryCommand = new NpgsqlCommand(query,conn);
NpgsqlDataReader dataReader = queryCommand.ExecuteReader();
while (dataReader.Read())
{
/ / Chart vullen
Console.WriteLine( {0} \t {1} \ n,dataReader [ 0 ],dataReader [ 1 跨度>]);
}
conn.Close();
Console.Write( 我执行了这个查询 +查询);
Console.ReadLine();
}
catch (例外e)
{
Console.Write(e.Message);
Console.ReadLine();
}
}
}
}
解决方案
< blockquote>看看这个CodeProject库:一个灵活的.NET图表库 [ ^ ]
可悲的是,根据他对文章的一些评论,作者似乎已经在几年前去世了......
如果您正在寻找交互式图表,那么这看起来很有希望: GitHub - 实时图表/实时图表:简单,灵活,交互式和放大器;强大的.Net图表,地图和仪表 [ ^ 一>
Hi everybody. I am using PgAdmin 4 as Database in order to put some query results in a chart. I can barely find good examples of codes in order to do it. Could anyone possibly help me with it or introduce me a good source?I am new to programming so my codes may not look really nice or professional. PLEASE HELPPPP
What I have tried:
using System;
using Npgsql;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DBConnectExperiment
{
class Program
{
static void Main(string[] args)
{
string query = "select count(fietsdiefstal.buurt), climat.tn from fietsdiefstal inner join climat on fietsdiefstal.year = climat.year group by (fietsdiefstal.buurt), climat.tn ";
string ip = "127.0.0.1";
string port = "5432";
string database = "project3";
string username = "project3";
string password = "project3";
string deliminator = ";";
string connectionParameter = String.Format("Server=" + ip + deliminator + "Port=" + port + deliminator + "User Id=" + username + deliminator + "Password=" + password + deliminator + "Database=" + database);
try
{
NpgsqlConnection conn = new NpgsqlConnection(connectionParameter);
Console.WriteLine("connection has been made");
conn.Open();
Console.WriteLine("database is openned ...");
NpgsqlCommand queryCommand = new NpgsqlCommand(query, conn);
NpgsqlDataReader dataReader = queryCommand.ExecuteReader();
while (dataReader.Read())
{
//Chart vullen
Console.WriteLine("{0} \t {1} \n", dataReader[0], dataReader[1]);
}
conn.Close();
Console.Write("I executed this query" + query);
Console.ReadLine();
}
catch (Exception e)
{
Console.Write(e.Message);
Console.ReadLine();
}
}
}
}
解决方案
Take a look at this CodeProject library: A flexible charting library for .NET[^]
Sadly, according to some comments on his article, the author seems to have passed away some years ago ...
If you are looking for interactive charts then this looks promising: GitHub - Live-Charts/Live-Charts: Simple, flexible, interactive & powerful charts, maps and gauges for .Net[^]
这篇关于如何在C#中创建显示查询结果的图表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文