Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
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();
            }


        }
    }
}
Posted
Updated 18-Mar-18 9:47am
v2
Comments
Kornfeld Eliyahu Peter 18-Mar-18 10:10am    
https://msdn.microsoft.com/en-us/library/system.windows.forms.datavisualization.charting(v=vs.110).aspx

1 solution

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[^]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900