Программно добавляете Диаграмму в Программу, но не показывает вывод диаграммы - PullRequest
0 голосов
/ 02 апреля 2019

Я создаю диаграмму динамически и соединяю ее с таблицей базы данных, чтобы показать вывод диаграммы, но мой источник данных диаграммы не смог получить таблицу базы данных, или я не знаю, почему не получаю вывод.В чем проблема источника данных или привязки данных?показывать графики

Chart addchart()
{
    Chart chartA = new Chart();
    SqlConnection cs = new SqlConnection(@"Data Source=LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\Task_2\Task_2\Database.mdf;Integrated Security=True");
    cs.Open();
    SqlCommand md=new SqlCommand("Select*from Agestatistics",cs);
    md.ExecuteNonQuery();
    cs.Close();
    try
    {
        Legend legend = new Legend();
        chartA.BackColor = Color.White;
        chartA.Location =new Point(t,l);
        chartA.Width = 370;
        chartA.Height = 250;
        chartA.Name = ""+x;
        chartA.Legends.Add(legend);
        legend.TitleFont = new Font(legend.Font.FontFamily, 7);
        //legend.Font = new Font("Arial", 8, FontStyle.Bold);
        legend.Title = "Age of the Employees";
        Series series;
        series = new Series(""+x );
        series[""+x] = "Disabled";
        series.IsValueShownAsLabel = true;
        series.LabelAngle = 0;
        series.Font = new Font("Arial", 8, FontStyle.Bold);
        // series.SmartLabelStyle.Enabled = true;
        series.ChartType = SeriesChartType.Pie;
        series.LegendToolTip = ("Age of The Employees");
        series.IsVisibleInLegend = true;
        chartA.Series.Add(series);
        ChartArea chartArea = new ChartArea();
        Axis yAxis = new Axis(chartArea, AxisName.Y);
        Axis xAxis = new Axis(chartArea, AxisName.X);
        chartA.Series["" + x].XValueMember = "" + x;
        chartA.Series["" + x].YValueMembers = "" + y;
        chartArea.AxisX.Title = "Age";
        chartArea.AxisY.Title = "Total";
        chartA.ChartAreas.Add(chartArea);
        chartA.Legends[0].ForeColor = Color.Blue;
        chartA.Series["" + x].LabelForeColor=Color.DarkGreen;
        chartA.Titles.Add("Age Statistics of The Employees");
        chartA.DataSource = md;                        
        chartA.DataBind();                        
        chartA.Show();
        control.Controls.Add(chartA);
        chartA.Show();                     
    }
    catch
    {
         MessageBox.Show("Connection Problem", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    return chartA;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...