This is a migrated thread and some comments may be shown as answers.

How to create dynamic chart legend in bar chart from database

3 Answers 511 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Diki
Top achievements
Rank 1
Diki asked on 03 Feb 2012, 07:58 AM
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

3 Answers, 1 is accepted

Sort by
0
Elian
Telerik team
answered on 06 Feb 2012, 06:54 PM
Hello Diki,

If you do not want the the items from the data-source to appear in the legend:

chart1.Series[0].Appearance.LegendDisplayMode = Charting.ChartSeriesLegendDisplayMode.Nothing;

If you want to programmatically add new items to the Legend:
chart1.Legend.Items.Add(new Charting.LabelItem(...));
Kind regards,
Elian
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Diki
Top achievements
Rank 1
answered on 07 Feb 2012, 05:58 AM

Hi Elian,

thanks for your respone.

Actually I need a simple way to create a Dynamic bar chart with multiple series and legend (sample chart picture is in attachment file). Where all the data is from database.

I have create chart in Telerik Asp Ajax, is very simple just add datasoure to the chart

then right click the chart to choose "properties" menu.

After that Chart Builder is showing up, then I only have setting in data tab form.

I dont know why I can do the same way to create a chart like in Telerik Asp Ajax.

Can anyone give me the best way to create a chart like I want in telerik reporting?

Best Regards,

Diki

0
Elian
Telerik team
answered on 07 Feb 2012, 06:05 PM
Hello Diki,

In the designer, if you right-click on the chart object and select Properties from the context menu you will get a Tabular chart builder dialog. Also, in our documentation you can find some helpful articles about charts: Building Charts

Regards,
Elian
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
General Discussions
Asked by
Diki
Top achievements
Rank 1
Answers by
Elian
Telerik team
Diki
Top achievements
Rank 1
Share this question
or