none
Dynamic chart in ssrs RRS feed

  • Question

  • hi

    here is the problem : I want to create a chart dynamically.

     

    for eg am having sales ,marketing,finance  as columns in dataset

     

    I want chart with  X-axis(category field ) to be either sales or marketing or finance  that depends upon the parameter passed by the user.

     

     

    I would appreciate for giving the solution for this problem.

    thanks in advance

    Thursday, May 29, 2008 12:42 PM

Answers

  • Hi,

     

    Here, I provide a sample for the dynamic chart.

     

    Code Snippet

    Code Snippet

    protected void btnViewReport_Click(object sender, EventArgs e)

    {

    Stream streamingReport;

    //The .rdlc file is actually an XML document that structures how the report is to be built.

    XmlDocument rdlcXML = new XmlDocument();

    try

    {

      streamingReport = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("ConsumerRaterReports.TransactionsByHour.rdlc");

      rdlcXML.Load(streamingReport);

      //Change out the Type of the chart in the XML document

      XmlNodeList typeNodeList = rdlcXML.GetElementsByTagName("Type");

      XmlNode typeNode = typeNodeList[0];

     

      if (uxChartType.Items[uxChartType.SelectedIndex].Text == "")

        typeNode.InnerText = "Line";

      else

        typeNode.InnerText = uxChartType.Items[uxChartType.SelectedIndex].Text;

     

      //Reset the basic report information

      ReportViewer1.Reset();

      ReportViewer1.ProcessingMode = ProcessingMode.Local;

      ReportDataSource newDataSource = new ReportDataSource();

      newDataSource.DataSourceId = "ObjectDataSource1";

      newDataSource.Name = "TransactionsByHour_vwGetConsumerStatsByHour";

      ReportViewer1.LocalReport.DataSources.Add(newDataSource);

      ReportViewer1.LocalReport.ReportPath = string.Empty; 

      ReportViewer1.LocalReport.LoadReportDefinition(new StringReader(rdlcXML.OuterXml));

      ReportViewer1.LocalReport.Refresh();

      }

      finally

      {

      streamingReport.Close();

      }

     

    ... (more code to set datasource and set report to visible)

     

     

     

     

    Hopefully this helps.

    Tuesday, June 3, 2008 8:13 AM

All replies

  • Base your category group on  an expression that checks for the value of the parameter.  That should do the trick.

     

    -Sean

    • Proposed as answer by ShaKri Wednesday, September 21, 2011 7:05 PM
    Thursday, May 29, 2008 5:11 PM
  • Hi,

     

    Here, I provide a sample for the dynamic chart.

     

    Code Snippet

    Code Snippet

    protected void btnViewReport_Click(object sender, EventArgs e)

    {

    Stream streamingReport;

    //The .rdlc file is actually an XML document that structures how the report is to be built.

    XmlDocument rdlcXML = new XmlDocument();

    try

    {

      streamingReport = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("ConsumerRaterReports.TransactionsByHour.rdlc");

      rdlcXML.Load(streamingReport);

      //Change out the Type of the chart in the XML document

      XmlNodeList typeNodeList = rdlcXML.GetElementsByTagName("Type");

      XmlNode typeNode = typeNodeList[0];

     

      if (uxChartType.Items[uxChartType.SelectedIndex].Text == "")

        typeNode.InnerText = "Line";

      else

        typeNode.InnerText = uxChartType.Items[uxChartType.SelectedIndex].Text;

     

      //Reset the basic report information

      ReportViewer1.Reset();

      ReportViewer1.ProcessingMode = ProcessingMode.Local;

      ReportDataSource newDataSource = new ReportDataSource();

      newDataSource.DataSourceId = "ObjectDataSource1";

      newDataSource.Name = "TransactionsByHour_vwGetConsumerStatsByHour";

      ReportViewer1.LocalReport.DataSources.Add(newDataSource);

      ReportViewer1.LocalReport.ReportPath = string.Empty; 

      ReportViewer1.LocalReport.LoadReportDefinition(new StringReader(rdlcXML.OuterXml));

      ReportViewer1.LocalReport.Refresh();

      }

      finally

      {

      streamingReport.Close();

      }

     

    ... (more code to set datasource and set report to visible)

     

     

     

     

    Hopefully this helps.

    Tuesday, June 3, 2008 8:13 AM
  • Another option would be as follows:

     

    1. Say, your DataSet/Database provides/has 3 columns   -  "A", "B", "C"

    2. Create 2 more Columns to this, say "X" & "Y"

    3. By default bind these 2 columns ("X" & "Y") as part of your X-Axis & Y-Axis in your report so that your report always looks for value only in these 2 columns

    4. Within your SQLCode/ DataSet Code populate "X" & "Y" from "A", "B", "C", based of your condition

     

    Hope this helps

     

    Thanks

    Prasanna

     

    Friday, June 27, 2008 2:31 PM