我正在將數值資料傳輸到笛卡爾圖中的圖表。但是,從資料庫中提取資料名稱時出現問題。名稱不出現。我希望我的資料在笛卡爾圖旁邊顯示為餅圖。我想將“GelirAdi”列中的資料與圖表相匹配。總之,“GelirAdi”列將是名稱,“GelirMiktari”將是笛卡爾圖中的數值,但我該怎么做?

private void btn_gider_bilgi_getir_Click(object sender, EventArgs e)
{
string veritabaniyolu = "Data source=veritabani.db";
bunifuDataGridView1.DataSource = null;
SQLiteConnection baglanti = new SQLiteConnection(veritabaniyolu);
baglanti.Open();
string sql_tarih_sorgula = "SELECT * FROM Gelirler";
SQLiteDataAdapter da = new SQLiteDataAdapter(sql_tarih_sorgula, baglanti);
DataTable dt = new DataTable();
da.Fill(dt);
bunifuDataGridView1.DataSource = dt;
baglanti.Close();
ColumnSeries series2 = new ColumnSeries()
{
DataLabels = true,
Values = new ChartValues<int>(),
LabelPoint = point => point.Y.ToString()
};
Axis axisX = new Axis() {
Separator = new Separator() { Step = 1, IsEnabled = false },
Labels=new List<string>()
};
Axis axisY = new Axis()
{
LabelFormatter=y=>y.ToString(),
Separator=new Separator()
};
cartesianChart1.Series.Add(series2);
cartesianChart1.AxisX.Add(axisX);
cartesianChart1.AxisY.Add(axisY);
foreach (DataGridViewRow item in bunifuDataGridView1.Rows) {
int a = Convert.ToInt32(item.Cells["GelirMiktari"].Value);
series2.Values.Add(a);
axisX.Labels.Add(item.Cells["GelirAdi"].Value.ToString());
}
}
uj5u.com熱心網友回復:
根據我的測驗,您可以使用 linq 動態設定標簽點的工具提示。
您可以嘗試以下代碼來實作它。
private void Form1_Load(object sender, EventArgs e)
{
SQLiteConnection m_dbConnection = new SQLiteConnection("Data Source=MyDatabase.sqlite");
m_dbConnection.Open();
SQLiteDataAdapter da = new SQLiteDataAdapter("select * from Product", m_dbConnection);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
dataGridView1.AllowUserToAddRows = false;
}
private void button1_Click(object sender, EventArgs e)
{
ColumnSeries series2 = new ColumnSeries()
{
DataLabels = true,
Values = new ChartValues<int>(),
LabelPoint = point => dataGridView1.Rows.Cast<DataGridViewRow>().Where(i => Convert.ToDouble(i.Cells["number"].Value) == point.Y).Select(i => i.Cells["name"].Value.ToString()).First(),
Title = "" //Here you added to remove "Series" text
};
Axis axisX = new Axis()
{
Separator = new Separator() { Step = 1, IsEnabled = false },
Labels = new List<string>()
};
Axis axisY = new Axis()
{
LabelFormatter = y => y.ToString(),
Separator = new Separator()
};
cartesianChart1.Series.Add(series2);
cartesianChart1.AxisX.Add(axisX);
cartesianChart1.AxisY.Add(axisY);
foreach (DataGridViewRow item in dataGridView1.Rows)
{
int a = Convert.ToInt32(item.Cells["number"].Value);
series2.Values.Add(a);
}
}
結果:

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/417837.html
標籤:
