Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Reporting > Telerik Reporting > How to create dynamic chart legend in bar chart from database

Not answered How to create dynamic chart legend in bar chart from database

Feed from this thread
  • Diki avatar

    Posted on Feb 3, 2012 (permalink)

    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

    Attached files

    Reply

  • Elian Elian admin's avatar

    Posted on Feb 6, 2012 (permalink)

    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 >>

    Reply

  • Diki avatar

    Posted on Feb 6, 2012 (permalink)

    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

    Reply

  • Elian Elian admin's avatar

    Posted on Feb 7, 2012 (permalink)

    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 >>

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Reporting > Telerik Reporting > How to create dynamic chart legend in bar chart from database
Related resources for "How to create dynamic chart legend in bar chart from database"

Features  |  Documentation  |  Demos  |  Telerik TV  |  Knowledge Base  |  Code Library  |  Step-by-step Tutorial  |  Blogs  |  Whitepaper  ]