Kentico CMS 6.0 Developer's Guide

Managing report graphs

Managing report graphs

Previous topic Next topic Mail us feedback on this topic!  

Managing report graphs

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

Arrow


API examples for newer versions


Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.



The following example creates a graph and assigns it to a report.

 

private bool CreateReportGraph()
{
    // Get report object by report code name
    ReportInfo report = ReportInfoProvider.GetReportInfo("MyNewReport");
 
    // If report exists
    if (report != null)
    {
        // Create new report graph object
        ReportGraphInfo newGraph = new ReportGraphInfo();
 
        // Set the properties
        newGraph.GraphDisplayName = "My new graph";
        newGraph.GraphName = "MyNewGraph";

       newGraph.GraphQuery = "SELECT TOP 10 DocumentName, DocumentID FROM CMS_Document";

        newGraph.GraphReportID = report.ReportID;
        newGraph.GraphQueryIsStoredProcedure = false;
        newGraph.GraphType = "bar";
 
        // Save the report graph
        ReportGraphInfoProvider.SetReportGraphInfo(newGraph);
 
        return true;
    }
 
    return false;
}

 

The following example gets and updates a report graph.

 

private bool GetAndUpdateReportGraph()
{

  // Get the report graph
  ReportGraphInfo updateGraph = ReportGraphInfoProvider.GetReportGraphInfo("MyNewGraph");

    if (updateGraph != null)
    {
        // Update the properties
        updateGraph.GraphDisplayName = updateGraph.GraphDisplayName.ToLower();
 
        // Save the changes
        ReportGraphInfoProvider.SetReportGraphInfo(updateGraph);
 
        return true;
    }
 
    return false;
}

 

The following example gets and bulk updates report graphs.

 

private bool GetAndBulkUpdateReportGraphs()
{
    // Prepare the parameters
    string where = "GraphName LIKE N'MyNewGraph%'";
 
    // Get the data
    DataSet graphs = ReportGraphInfoProvider.GetGraphs(where, null);
    if (!DataHelper.DataSourceIsEmpty(graphs))
    {
        // Loop through the individual items
        foreach (DataRow graphDr in graphs.Tables[0].Rows)
        {
            // Create object from DataRow
            ReportGraphInfo modifyGraph = new ReportGraphInfo(graphDr);
 
            // Update the properties
            modifyGraph.GraphDisplayName = modifyGraph.GraphDisplayName.ToUpper();
 
            // Save the changes
            ReportGraphInfoProvider.SetReportGraphInfo(modifyGraph);
        }
 
        return true;
 
    }
    return false;
}

 

The following example deletes a report graph.

 

private bool DeleteReportGraph()
{

  // Get the report graph
  ReportGraphInfo deleteGraph = ReportGraphInfoProvider.GetReportGraphInfo("MyNewGraph");

 
    // Delete the report graph
    ReportGraphInfoProvider.DeleteReportGraphInfo(deleteGraph);
 
    return (deleteGraph != null);
}