Control X-axis markings in date data charts

Asked

Viewed 142 times

0

I have records in the database and a graph where I can visualize them. The graph is of data x voltage in volts.

When I have few records in the table the chart shows exactly the date recorded in the database on the X axis, but along when I add more records the chart grows and stops to mark all the date records where there was voltage variation.

I’m putting up an image of how the chart looks:

inserir a descrição da imagem aqui

This graph is taking 50 entries from my bank with different hours and voltage values.

I would like a way to improve and be able to better control the points of the X axis, maybe making them appear every 10 minutes for example.

Below is the code that generates the graphics:

    SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStringSQL"].ConnectionString);
    con.Open();
    SqlCommand cmd = new SqlCommand("SELECT Log.ValorEntrada, Log.DataHoraEvento, Log.NumeroEntrada FROM Log INNER JOIN Equipamento ON Log.IDEquipamento = Equipamento.IDEquipamento INNER JOIN EntradaEstado ON Equipamento.IDEquipamento = EntradaEstado.IDEquipamento INNER JOIN Entrada ON EntradaEstado.IDEntrada = Entrada.IDEntrada WHERE Log.NumeroEntrada = N'" + descricao.SelectedItem.Value + "' AND Log.ValorEntrada IS NOT NULL AND DATEDIFF(day, Log.DataHoraEvento, GETDATE()) = 1 AND EntradaEstado.IDEquipamento = N'" + equip.Text + "' AND Entrada.Descricao = N'" + descricao.SelectedItem.Text + "' ORDER BY DataHoraEvento ASC");
    cmd.Connection = con;
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    da.Fill(dt);

    if (dt.Rows.Count > 0)
    {
        Chart2.DataSource = dt;

        if (descricao.SelectedItem.Text == "Corrente da bomba de graxa")
        {
            Chart2.ChartAreas["ChartArea1"].AxisY.Title = "Corrente (A)";
        }
        else
        {

            Chart2.ChartAreas["ChartArea1"].AxisY.Title = "Tensão (V)";
        }

        Title title = Chart2.Titles.Add("Gráfico do dia: " + DateTime.Now.AddDays(-1).ToString("dd/MM/yyyy"));
        title.ForeColor = System.Drawing.Color.DarkBlue;
        title.Font = new System.Drawing.Font("Arial", 12, System.Drawing.FontStyle.Bold);




        Chart2.ChartAreas["ChartArea1"].AxisX.Title = "Hora";
        Chart2.ChartAreas["ChartArea1"].AxisX.LabelStyle.Format = "HH:mm:ss";
        Chart2.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineColor = System.Drawing.Color.DarkGray;
        Chart2.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineDashStyle = ChartDashStyle.Dot;
        Chart2.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineColor = System.Drawing.Color.DarkGray;
        Chart2.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dot;


        Chart2.Series["Series1"].XValueType = ChartValueType.DateTime;
        Chart2.Series["Series1"].BorderWidth = 2;
        Chart2.Series["Series1"].XValueMember = "DataHoraEvento";
        Chart2.Series["Series1"].YValueMembers = "ValorEntrada";
        Chart2.Series["Series1"].IsXValueIndexed = true;

        Chart2.Width = 1200;
        Chart2.Height = 400;

        Chart2.DataBind();
        con.Close();
  • tries to change in Series1, the Markerstep property

  • It didn’t work......

No answers

Browser other questions tagged

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