Hi All,
I have try to create a bar chart from database,but I have no clue to make dynamic chart legend data from database.
Can anyone give example for me..?
========= This is my Code ======================
private void chart1_NeedDataSource(object sender, System.EventArgs e)
{
this.chart1.Series.Clear();
String pPeriodeStart = Convert.ToString(this.ReportParameters["PeriodeStart"].Value);
String pPeriodeUntil = Convert.ToString(this.ReportParameters["PeriodeUntil"].Value);
if (pPeriodeStart == "") pPeriodeStart = "null"; else pPeriodeStart = "'" + pPeriodeStart + "'";
if (pPeriodeUntil == "") pPeriodeUntil = "null"; else pPeriodeUntil = "'" + pPeriodeUntil + "'";
string sql = @"exec dbo.procedureName @PeriodeStart = " + pPeriodeStart+ ", @PeriodeUntil = " + pPeriodeUntil;
string connectionString =
"Data Source=xxx-pc\\SQLEXPRESS;Initial Catalog=dbname;Persist Security Info=True;User ID=sa;Password=password";
SqlDataAdapter adapter = new SqlDataAdapter(sql, connectionString);
DataSet dataSet = new DataSet();
adapter.Fill(dataSet);
ChartSeries series = new Telerik.Reporting.Charting.ChartSeries();
series.DataYColumn = "AuctionDealValue";
series.Appearance.LabelAppearance.Visible = true;
//series.Appearance.ShowLabelConnectors = true;
series.Appearance.ShowLabels = true;
series.Appearance.LegendDisplayMode = Telerik.Reporting.Charting.ChartSeriesLegendDisplayMode.ItemLabels;
//this.chart1.DataGroupColumn = "StakeholderId";
this.chart1.ChartTitle.TextBlock.Text = "Test";
this.chart1.PlotArea.XAxis.AutoScale = false;
this.chart1.PlotArea.XAxis.AddRange(1, 10, 1);
this.chart1.PlotArea.XAxis.DataLabelsColumn = "CommodityName";
this.chart1.Series.Add(series);
(sender as Telerik.Reporting.Processing.Chart).DataSource = dataSet.Tables[0].DefaultView;
}
============= end of code ===============
+++++++++ this is my data from store procedure ++++++++++++++++
AuctionDealValue StakeholderName CommodityName CommodityId StakeHolderId
36.475000000 fedde1 Jagung 1 bures1
271.723100000 fedde2 Kayu Jati 2 bures1
47.050000000 fedde3 Kakao 3 bures2
+++++++++ this is my data from store procedure ++++++++++++++++
Regards,
Diki
I have try to create a bar chart from database,but I have no clue to make dynamic chart legend data from database.
Can anyone give example for me..?
========= This is my Code ======================
private void chart1_NeedDataSource(object sender, System.EventArgs e)
{
this.chart1.Series.Clear();
String pPeriodeStart = Convert.ToString(this.ReportParameters["PeriodeStart"].Value);
String pPeriodeUntil = Convert.ToString(this.ReportParameters["PeriodeUntil"].Value);
if (pPeriodeStart == "") pPeriodeStart = "null"; else pPeriodeStart = "'" + pPeriodeStart + "'";
if (pPeriodeUntil == "") pPeriodeUntil = "null"; else pPeriodeUntil = "'" + pPeriodeUntil + "'";
string sql = @"exec dbo.procedureName @PeriodeStart = " + pPeriodeStart+ ", @PeriodeUntil = " + pPeriodeUntil;
string connectionString =
"Data Source=xxx-pc\\SQLEXPRESS;Initial Catalog=dbname;Persist Security Info=True;User ID=sa;Password=password";
SqlDataAdapter adapter = new SqlDataAdapter(sql, connectionString);
DataSet dataSet = new DataSet();
adapter.Fill(dataSet);
ChartSeries series = new Telerik.Reporting.Charting.ChartSeries();
series.DataYColumn = "AuctionDealValue";
series.Appearance.LabelAppearance.Visible = true;
//series.Appearance.ShowLabelConnectors = true;
series.Appearance.ShowLabels = true;
series.Appearance.LegendDisplayMode = Telerik.Reporting.Charting.ChartSeriesLegendDisplayMode.ItemLabels;
//this.chart1.DataGroupColumn = "StakeholderId";
this.chart1.ChartTitle.TextBlock.Text = "Test";
this.chart1.PlotArea.XAxis.AutoScale = false;
this.chart1.PlotArea.XAxis.AddRange(1, 10, 1);
this.chart1.PlotArea.XAxis.DataLabelsColumn = "CommodityName";
this.chart1.Series.Add(series);
(sender as Telerik.Reporting.Processing.Chart).DataSource = dataSet.Tables[0].DefaultView;
}
============= end of code ===============
+++++++++ this is my data from store procedure ++++++++++++++++
AuctionDealValue StakeholderName CommodityName CommodityId StakeHolderId
36.475000000 fedde1 Jagung 1 bures1
271.723100000 fedde2 Kayu Jati 2 bures1
47.050000000 fedde3 Kakao 3 bures2
+++++++++ this is my data from store procedure ++++++++++++++++
Regards,
Diki