Populate chart with mysql data

Asked

Viewed 783 times

1

I am developing an application in C# and need to fill a graph with the amount of data registered in 3 Mysql tables. It is as follows: The graphic should inform the user in different columns how many data are registered in the product tables, logged and logged respectively, as in the image below:

tabela de dados

I have a hard time making that happen. Follow image with graph in form:

gráfico no formulário

Connection string:

public class DadosDaConexao
{
    public static String servidor = "%";
    public static String banco = "estoque_box";
    public static String usuario = "estBox";
    public static String senha = "estoqueBox";
    public static String StringDeConexao
    {
        get
        {
            return "Server=" + servidor + ";Database=" + banco + ";Uid=" + usuario + ";Pwd=" + senha;
        }
    }
}

I think this might help:

public void loadChart()
    {
        MySqlConnection conexao = new MySqlConnection();
        conexao.ConnectionString = DadosDaConexao.StringDeConexao;
        conexao.Open();
        string Query = "select count(*) from produto where pro_cod;";
        MySqlCommand cmdDataBase = new MySqlCommand(Query, conexao);
        MySqlDataReader myReader;
        try
        {
            myReader = cmdDataBase.ExecuteReader();
            while (myReader.Read())
            {
                this.GrProdutos.Series["Produto"].Points.AddXY(myReader.GetString("pro_cod"), myReader.GetString("pro_cod"));
            }

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
        conexao.Close();
    }
  • Some tips: 1. do not use tag visual-studio if the problem is unrelated to the IDE. If you have any questions, I recommend reading: What is a programming language, IDE and compiler?; 2. Show us what you have already tried, preferably add a [mcve]; 3. Try to explain the difficulty you are having, in the current form the question is very wide and possibly will be closed so.

  • I have already added to the chart, however no function has been added to it

  • When you run the query in the database, what is your method returning a Datatable ? Put there in question how you are doing the query.

  • I added the code @Robss70

1 answer

1


Your error is in SQL

select count(*) from produto where pro_cod;

Is missing Cod parameter ex:

select count(*) from produto where pro_cod = 1 group by parametrodeAgrupamento;

something else if you want to use the column pro_cod she must come in select,

select count(*) as count, pro_cod from produto where pro_cod = 1 group by parametrodeAgrupamento;

About the orientation of the chart you are adding equal values in x and y

This will not work very well, need to review what you need-mind you want to display on the chart Tip do not go by trial and error, intenda what you are doing to then do.

use in this way

myReader.GetString("count")

Browser other questions tagged

You are not signed in. Login or sign up in order to post.