Littlebobbydroptables
Littlebobbydroptables

Reputation: 3731

Visual Studio, C# detailed chart

I am creating small program what shows us total sell sum by months via chart, but my chart is not detailed enough, it shows for example what sum in 2012'07 was something between 20 and 40, but i need exact value. (32,4)

enter image description here

Help needed.

Code

 private void formGraph()
    {
        string database, host, user, pass, sqlParams, sqlQuery;
        string resultPassword = String.Empty;

        database = "";
        host = "localhost";
        user = "";
        pass = "";

        sqlParams = "Database=" + database + ";Data Source=" + host + ";User Id=" + user + ";Password=" + pass;
        sqlQuery = "SELECT YEAR(`importdate`) as 'Year', MONTH(`importdate`) as 'Month', SUM(`price`) as 'Sum' FROM `data` GROUP BY MONTH(`importdate`), YEAR(`importdate`) ORDER BY YEAR(`importdate`), MONTH(`importdate`) ASC LIMIT 12";

        MySqlConnection sqlConnection = new MySqlConnection(sqlParams);
        MySqlCommand sqlCommand = new MySqlCommand(sqlQuery, sqlConnection);

        try
        {
            sqlConnection.Open();

            MySqlDataReader sqlReader = sqlCommand.ExecuteReader();

            if (sqlReader.HasRows)
            {
                while (sqlReader.Read())
                {
                    string Sum = sqlReader["Sum"].ToString();
                    if (Sum.Contains(",")) Sum = Sum.Replace(",", ".");
                    if (Sum == "0") Sum = "1";
                    chart1.Series.Add(sqlReader["Year"].ToString() + '\'' + sqlReader["Month"].ToString());
                    chart1.Series[sqlReader["Year"].ToString() + '\'' + sqlReader["Month"].ToString()].Points.AddY(Sum);
                    //sqlReader["Year"].ToString() + '"' + sqlReader["Month"].ToString()
                }
            }
        }
        catch (MySqlException sqlError)
        {
            MessageBox.Show("Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        finally
        {
            sqlConnection.Close();
        }
    }

Upvotes: 4

Views: 2554

Answers (2)

FrostyFire
FrostyFire

Reputation: 3258

You need to go through all the series you have and set the IsValueShownAsLabelproperty to true. Like this, to do the very first one:

Chart1.Series[0].IsValueShownAsLabel = true;

Hope this helps you!

Upvotes: 3

JanT
JanT

Reputation: 2096

Chart1.Series(Series1.Name).Font = New System.Drawing.Font("Arial", 10.0F, System.Drawing.FontStyle.Italic)

If you replace Series1.Name with yours it should work = display value on top of the column

Chart1.Series(Series1.Name).IsValueShownAsLabel = True;

Upvotes: 3

Related Questions