У меня есть datagridview, который пользователь заполняет. результат вычисляется и возвращает только столбцы readatridview только для чтения. Я хочу сделать диаграмму для двух столбцов моего документа datagridview. но я не сохраняю datagridview в таблице, потому что в таблице есть предыдущие результаты! Кто-то сказал мне, что для создания диаграммы вы должны сохранить свой datagridview в таблице, но в этом случае вам следует преобразовать datagridview в datatable, а затем очистить его! скажите, пожалуйста, что мне делать! :( это мой код для создания диаграммы, но она возвращает пустую таблицу! (У меня есть 19 колонок в моем DataGridView)создание диаграммы из datagridview
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace finalproject
{
public partial class Time_chart_Form : Form
{
private DataGridView DGV;
public Time_chart_Form(DataGridView DGV)
{
InitializeComponent();
this.DGV = DGV;
}
private void Time_chart_Form_Load(object sender, EventArgs e)
{
using (DataTable table = new DataTable("MyTable"))
{
DataRow newRow;
table.Columns.Add(new DataColumn("Time", typeof(string)));
table.Columns.Add(new DataColumn("Concentration", typeof(string)));
int column;
for (int i = 0; i < this.DGV.Rows.Count; i++)
{
column = 0;
newRow = table.NewRow();
if (!this.DGV[column, i].FormattedValue.Equals(""))
newRow["Time"] = this.DGV[0, i].Value.ToString();
else
newRow["Time"] = null;
column = 16;
if (!this.DGV[16, i].FormattedValue.Equals(""))
newRow["Concentration"] = this.DGV[column, i].Value.ToString();
else
newRow["Concentration"] = null;
table.Rows.Add(newRow);
}
Chart chart = new Chart();
chart.Width = 1600;
chart.Height = 900;
Series Series = new Series();
Series.Name = "Series";
Series.Color = Color.Red;
Series.BorderColor = Color.FromArgb(255, 0, 0);
Series.ChartType = SeriesChartType.Point;
Series.BorderDashStyle = ChartDashStyle.Solid;
//Series.BorderWidth = 10000;
Series.ShadowColor = Color.FromArgb(128, 128, 128);
Series.ShadowOffset = 0;
Series.BorderColor = Color.FromArgb(0, 0, 0);
//Chart Area-------------------------
ChartArea ca1 = new ChartArea();
ca1.Name = "ChartArea";
ca1.BackColor = Color.White;
ca1.BorderColor = Color.FromArgb(255, 255, 255);
ca1.BorderWidth = 10;
ca1.BorderDashStyle = ChartDashStyle.Solid;
ca1.AxisX = new Axis();
ca1.AxisY = new Axis();
chart.BackColor = Color.FromArgb(255, 255, 255);
chart.BackSecondaryColor = Color.White;
chart.BackGradientStyle = GradientStyle.TopBottom;
ca1.BackColor = System.Drawing.Color.FromArgb(64, System.Drawing.Color.White);
chart.ChartAreas.Add(ca1);
chart.Series.Add(Series);
chart.Series["Series"].BorderWidth = 500;
chart.Series["Series"].Points.DataBindXY(table.DefaultView, DGV.Columns[0].Name, table.DefaultView, DGV.Columns[16].Name);
chart.ChartAreas[0].AxisY.Minimum = -6;
chart.ChartAreas[0].AxisY.Maximum = 6;
chart.ChartAreas[0].AxisX.Minimum = 0;
chart.ChartAreas[0].AxisX.Maximum = 10;
chart.ChartAreas[0].AxisX.Interval = 1;
chart.ChartAreas[0].AxisY.Interval = 1;
chart.Titles.Add(new Title("OverView Plot", Docking.Top, new Font("Verdana", 19.5f, FontStyle.Bold), Color.Black));
chart.ChartAreas[0].AxisY.Title = "Time";
chart.ChartAreas[0].AxisX.Title = "Concentration";
chart.ChartAreas[0].AxisX.TitleFont = new System.Drawing.Font("Verdana", 19, FontStyle.Bold);
chart.ChartAreas[0].AxisY.TitleFont = new System.Drawing.Font("Verdana", 19, FontStyle.Bold);
chart.ChartAreas[0].AxisX.LabelStyle.Font = new System.Drawing.Font("Verdana", 19.25f, System.Drawing.FontStyle.Bold);
chart.ChartAreas[0].AxisY.LabelStyle.Font = new System.Drawing.Font("Verdana", 19.25f, System.Drawing.FontStyle.Bold);
chart.SaveImage(@"C:\Users\Maryam\Documents\Visual Studio 2010\prjchart" + (0).ToString() + ".png", ChartImageFormat.Png);
//table.Clear();
}
}
}
}