Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Automating Graph
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire de rapports & Rapports
Divers
Thread ID:
00614775
Message ID:
00614883
Vues:
20
This message has been marked as a message which has helped to the initial question of the thread.
Hello Jaime.

I would like to give my users the option to print either data or graph, either to preview or to printer. Is it possible to implement this in a straightforward manner? I was thinking about creating an XLS file with the result cursor for my report in case of a graph output and then try to automate an Excel application object to preview or print the graph.

The following code should be enough to get you started. What I do is have a single "seed" graph in a general field in a cursor. I then use the APPEND GENERAL command with the DATA clause to udate the graph in an OLEBound control on the form. This is the code in my UpdateGraph() method which assumes that the cursor with the graph data is csrResults and the cursor with the general field is csrGraph:
LOCAL lcGraphData, lnFld, lnFieldCount

*** Make the oleBoundControl invisible
*** and unbind it so we can update the general field
Thisform.LockScreen = .T.
Thisform.oGraph.ControlSource = ''
	
*** Now build the string we need to update the graph
*** in the general field
lcGraphData = ""
	
SELECT csrResults
lnFieldCount = FCOUNT()
	
*** Build tab-delimited string of field names:
FOR lnFld = 1 TO lnFieldCount  
  lcGraphData = lcGraphData + FIELD( lnFld ) ;
     + IIF( lnFld < lnFieldCount, CHR( 9 ), CHR( 13 ) + CHR( 10 ) )
ENDFOR

*** Concatenate the data, converting numeric fields to character:
SCAN
  FOR lnFld = 1 TO lnFieldCount  
    lcGraphData = lcGraphData + TRANSFORM( EVALUATE( FIELD( lnFld ) ) ) + ;
       + IIF( lnFld < lnFieldCount, CHR( 9 ), CHR( 13 )  + CHR( 10 ) )
  ENDFOR
ENDSCAN

GO TOP IN csrResults

*** OK, ready to update the graph
SELECT csrGraph
APPEND GENERAL oleGraph CLASS "MsGraph.Chart" DATA lcGraphData

WITH Thisform.oGraph
  *** Reset the controlSource of the OleBound control
  .ControlSource = "csrGRaph.oleGraph"

  *** Set the chart type
  .object.ChartType = Thisform.cboGraphType.Value

  *** Set the data to graph the columns as the series
  *** Unless, of course, this is a pie chart
  IF NOT INLIST( .ChartType, xl3DPie, xlPie, xlPieOfPie, xlPieExploded, xl3DPieExploded, xlBarOfPie )
    .Object.Application.PlotBy = xlColumns
  ELSE
    .Object.Application.PlotBy = xlRows
  ENDIF
ENDWITH

Thisform.LockScreen = .F.
The MsGraph object model is just a cut-down version of Excel's graphing engine. So the easiest thing to do if use VbaGrp9.chm to find the PEMs you are interested in and then look them up in the Excel documentation.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform