CrystalReportViewer Display a Graph Only - Not blank white space

Last post 07-13-2007 11:07 AM by Jodda. 4 replies.

Sort Posts:

  • CrystalReportViewer Display a Graph Only - Not blank white space

    07-12-2007, 6:11 AM
    • Loading...
    • Jodda
    • Joined on 08-16-2002, 4:47 AM
    • South Wales, UK
    • Posts 51

    Hi There,

    I have a CrystalReportViewer control to display a line graph on an ASPX page, but it displays a large amount of white space to the right and below the graph causing the scroll bar to appear.

    How can I display just the graph only? Is there an export option to display the graph as an image? Any help would be greatly appreciated.

  • Re: CrystalReportViewer Display a Graph Only - Not blank white space

    07-12-2007, 4:51 PM
    • Loading...
    • pontupo
    • Joined on 06-12-2007, 12:30 PM
    • Posts 85

     Well, I'll admit that this is a pretty outlandish work-around, but you could use something like this to automatically export your crystal report:

    1    Option Strict On
    2 Imports
    CrystalDecisions.CrystalReports.Engine
    3 Imports CrystalDecisions.Shared
    4 Imports
    System.Net.Mail
    5
    6 Partial Class _Default
    7 Inherits System.Web.UI.Page
    8
    9 Private stage7Detail As ReportDocument
    10 Private reportDB As Database
    11 Private reportTables As Tables
    12 Private reportTable As Table
    13 Private reportLogOnInfo As TableLogOnInfo
    14 Private dateToday As Date = Date.Today
    15 Private exportPath As String = "d:\IIS Web Roots\intranet\cf_sched1\crystal\" 'path to export the report to for auto-export
    16 ' these declarations are for a more complicated export scenario. Leaving them in for future reference.
    17 'Private myDiskFileDestinationOptions As DiskFileDestinationOptions
    18 'Private myExportOptions As ExportOptions
    19 'Private selectedNoFormat As Boolean = False
    20
    21 'our configuration method. Controls the session setup, loading of report, setting of
    22 'connection information, etc.

    23 Private Sub ConfigureCrystalReport()
    24 If (Session("stage7Detail") Is Nothing) Then 'if the report isn't in the session (first load)
    25 stage7Detail = New ReportDocument()
    26 'load the report document
    27 stage7Detail.Load("D:\IIS Web Roots\intranet\cf_sched1\crystal\AutomaticDailyStage7-Detail.rpt") 'web server
    28 'stage7Detail.Load("C:/Documents and Settings/cfry/Desktop/Web_Reports/Stage7Detail-Q1-new/Stage7-Detail-Y2D.rpt") 'local
    29
    30 'authenticate to the database

    31 reportDB = stage7Detail.Database 'get the database
    32 reportTables = reportDB.Tables 'get the tables
    33 'iterate through all of the tables, setting the correct login information for all of them

    34 For Each reportTable In reportTables
    35 reportLogOnInfo = reportTable.LogOnInfo 'get the LogOnInfo object
    36 'reportLogOnInfo.ConnectionInfo.ServerName = "server" 'specify the server.
    37 'reportLogOnInfo.ConnectionInfo.DatabaseName = "database" 'specify the database
    38 'reportLogOnInfo.ConnectionInfo.UserID = "username" 'specify the user name

    39 reportLogOnInfo.ConnectionInfo.Password = "password" 'specify the password
    40 reportTable.ApplyLogOnInfo(reportLogOnInfo) 'save the changes
    41 Next reportTable
    42
    43 Session("stage7Detail") = stage7Detail 'save the report to the session
    44 Else
    45 stage7Detail = CType(Session("stage7Detail"), ReportDocument) 'otherwise load the report
    46 End If
    47
    48 Stage7DetailViewer.DisplayGroupTree = False 'hide the group tree
    49 Stage7DetailViewer.ReportSource = stage7Detail 'set the viewer source to the report object
    50 End Sub
    51
    52 'the on-load function merely launches the ConfigureCrystalReport() method
    53 'that method will do any actual setup that's required.

    54 Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
    55 ConfigureCrystalReport()
    56 ExportSetup()
    57 ExportReport()
    58 End Sub
    59 'Setup the file export. Basically concerned with setting the correct values for:
    60 'Private exportPath As String

    61
    62 Public Sub ExportSetup()
    63 'Note: If you want to place the Exported folder within the Web directory of your Web server,
    64 'prefix the folder name with the Request.PhysicalApplicationPath property. (from VS help)

    65 If Not System.IO.Directory.Exists(exportPath) Then 'check if the directory exists
    66 System.IO.Directory.CreateDirectory(exportPath) 'and create it if it doesn't
    67 End If
    68 End Sub
    69 Public Sub
    ExportReport()
    70 Dim myFileName As String = ""
    71 myFileName = exportPath & "OrderManagementReport_" & Format(dateToday, "MMddyyyy") & ".pdf"
    72 stage7Detail.ExportToDisk(ExportFormatType.PortableDocFormat, myFileName)
    73 End Sub

    This will get your report automatically exported to (in this case) a PDF in the specified directory. You can then put another 
    function call after line 57 to load the exported PDF up into the browser. It is also possible to export the PDF directly into
    the browser (or a new browser window) which I have samples of as well, but haven't tested and so can't be sure that my
    sample code works as is. Hopefully this example might lead you in a helpful direction,
     Pont 
     PS: Mind you, the exported PDF will be the same size as your report. It's possible that your extra whitespace isn't caused by being loaded
    into ASP, but rather is in the report itself... *shrug*
  • Re: CrystalReportViewer Display a Graph Only - Not blank white space

    07-13-2007, 9:31 AM
    • Loading...
    • Jodda
    • Joined on 08-16-2002, 4:47 AM
    • South Wales, UK
    • Posts 51

    Hi puntupo thanks for the reply, unfortunatley I don't wish to write a PDF or any other document to file. I wish to display ONLY a graph from a CrystalReport, within a web pages interface.

    A CrystalReportViewer control "does what it says on the tin" allows you to view/embed a CR into an ASPX page. Using the CrystalReportViewer control, embeds a large canvas area; instead of automatically recognising the size of the graph area, and embeding a canvas area the size of the graph/object. Which by the way, a graph's size can be adjusted when designing the RPT file. The CS (.rpt) contains a graph in the header section and that's all, no repeating text, no page count, no date time stamp nothing, only a graph.

    The perfect solution would be similar to the following sinario: <img src="GetGraphFromCR.aspx" />

    The overall result I'm trying to acheive is to display a series of graphs showing sales statistics for an admin section page of an Ecom website. Similar grouping of graphs to GoogleAnalytics summary page.

  • Re: CrystalReportViewer Display a Graph Only - Not blank white space

    07-13-2007, 9:56 AM
    • Loading...
    • pontupo
    • Joined on 06-12-2007, 12:30 PM
    • Posts 85

    Hmm, I do see what you're saying. That sounds like a tough problem, I'm not sure there is any way to get just the graph object out of Crystal and would be curious about what, if any, way you find of doing that =) Is it possible that you could adjust the settings of the CrystalReportViewer object so that it is the same size as your graph? If the graph is always going to be the same size, perhaps there is a way to specify the size of the viewer. At a glance, I saw options in the properties for BestFitPage, etc. which you might be able to use to manually specify the size of the report. If you then strip out the group tree and the toolbar, perhaps you could get it to fit properly?

    Sorry I don't have better to offer =/

    Pont 

  • Re: CrystalReportViewer Display a Graph Only - Not blank white space

    07-13-2007, 11:07 AM
    • Loading...
    • Jodda
    • Joined on 08-16-2002, 4:47 AM
    • South Wales, UK
    • Posts 51

    Yes I've tried changing various CrystalReportViewer controls attribute values with no luck. There's also a CrystalReportPartsViewer control to use, but have yet to work out how to bind a specific CR area via the ReportPartsDefinition class.

    Thanks for your input, I'll continue down the CrystalReportPartsViewer path for now hoping to discover an answer.

Page 1 of 1 (5 items)
Microsoft Communities
Page view counter