Chapter 24:
Java Functions
 

ReadJAVAScriptChartFile(); Read JAVA Script Chart File

 

WriteJAVAScriptChartFile(); Write JAVA Script Chart File

ReadJAVAScriptChartFile()

 

This function is used to read a JAVA Script file into PGSDK. The JAVA script file must have been generated by the Three |D| Graphics Perspective for Java product.

Syntax:

PUBLIC INT16
ReadJAVAScriptChartFile(
     GraphPtr pGraph,
     DrawEnvPtr pDE,
     char * pszFullPathName
);

Input:

pGraph: Pointer to the graph object created by AllocGraphPtr(). The graph object must be allocated before the ReadJAVAScriptChartFile() function is called.

 

pDE: Pointer to a draw environment created by AllocDrawEnvPtr() or NULL. If NULL is used, functionality to set the draw environment background rectangle will not be operational.

 

pszFullPathName; Full path name identifying the name and location of the Java script file to read. It must be "C" style string containing the full pathname of the Javascript file to read from.

Return:

INT16;

 

kREADJAVASCRIPTFILE_ERRORNONE

0

Success

 

kREADJAVASCRIPTFILE_ERROROPENINGFILE

100

Error opening file

 

kREADJAVASCRIPTFILE_ERRORFEATURENOTENABLED

200

Feature not enabled

 

kREADJAVASCRIPTFILE_ERRORFEATURENOTENABLED indicates the current version of PGSDK does not support the Read/Write to JAVA script feature. This feature is enabled based on specific customer request. Contact Three |D| Graphics for details.

Example:

// CGraph::LoadChartFromJAVAScriptFile
// Description: Load a graph from a JAVAScriptFile
//=================================
int CGraph::LoadChartFromJAVAScriptFile(
     const CString& szFileName )
{
     CString szShortFileName = szFileName;
     INT16 nErrorReturnCode;
     InitDataCallBacks();// Set the callbacks
     nErrorReturnCode = ::ReadJAVAScriptChartFile(
          m_pGraph,// IN: Ptr to the Graph is manditory
          0,// IN: No Draw Env, add one if possible
          szShortFileName.GetBuffer(0));// IN: Filename
     return(0);// Don't handle the error for now
}

Notes:

1.

See the Perspective for Java Programmer's Manual for details about each Attribute and corresponding Javascript "set" function.

 

2.

See the PGSDK-to-JavaScript Cross-Reference the PGSDK Programmer's Manual for a complete list of PGSDK objects, attributes, and API functions that can be translated to Java script.

 

3.

The following JavaScript commands are translated by ReadJAVAScriptChartFile():

   

>

setAutofit

   

>

setAxisAssignment

   

>

setBorderColor

   

>

setColorMode

   

>

setData, setDataRange

   

>

setDataTextDisplay, setDataTextFormat, & setDataTextPosition

   

>

setDepthAngle, setDepthRadius

   

>

setDisplay

   

>

setDisplay3DFloor, setDisplay3DLeftWall, & setDisplay3DRightWall

   

>

setDisplayBarAsPictograph

   

>

setDualAxisLineDisplay

   

>

setFillColor

   

>

setFontName, setFontSizeVC, setFontStyle

   

>

setFootnoteDisplay, setFootnoteString

   

>

setFrameDisplay

   

>

setGraphType

   

>

setGroupLabel

   

>

setGrid3DFloorDisplayX, setGrid3DFloorDisplayZ

   

>

setGrid3DLeftWallDisplayY, setGrid3DLeftWallDisplayZ

   

>

setGrid3DRightWallDisplayX, setGrid3DRightWallDisplayY

   

>

setGrid3DRiserDisplayX, setGrid3DRiserDisplayY, setGrid3DRiserDisplayZ

   

>

setGroupLabelArray

   

>

setLegendAutomatic, setLegendDisplay, setLegendRect

   

>

setLineWidth

   

>

setMarkerShape, setMarkerSize

   

>

setO1AxisLineDisplay, setO1AxisSide, setO1LabelAutofit, setO1LabelDisplay, setO1LabelStagger, setO1MajorGridDisplay, setO1MinorGridDisplay

   

>

setO2LabelAutofit, setO2LabelDisplay

   

>

setPieDepth, setPieFeelerTextDisplay, setPieRingSize, setPieRingTotalDisplay, setPieRingTotalFormat, setPieRotate, setPieSliceDelete, setPiesPerRow, setPieTilt

   

>

setQuadrantLineCountX, setQuadrantLineCountY, setQuadrantLineValueX, setQuadrantLineValueY

   

>

setRect

   

>

setReverseSeries

   

>

setRiser3DThicknessY, setRiserBarGroupSpacing, setRiserWidth

   

>

setScaleFromZero

   

>

setSeriesAreRows, setSeriesLabel, setSeriesLabelArray

   

>

setSquareMarkers

   

>

setStockCloseTicksDisplay, setStockOpenTicksDisplay

   

>

setSubtitleDisplay, setSubtitleString

   

>

setTextString, setTextRotation

   

>

setTitleDisplay, setTitleString

   

>

setTransparentBorderColor, setTransparentFillColor

   

>

setX1AxisDescending, setX1AxisLineDisplay, setX1AxisSide, setX1LabelAutofit, setX1LabelDisplay, setX1LabelFormat, setX1LabelStagger, setX1LogScale, setX1MajorGridDisplay, setX1MajorGridStepAuto, setX1MajorGridStyle, setX1MinorGridDisplay, setX1MinorGridStepAuto, setX1MinorGridStyle, setX1MustIncludeZero, setX1OffScaleDisplay, setX1ScaleMax, setX1ScaleMaxAuto, setX1ScaleMin, setX1ScaleMinAuto, setX1TitleDisplay, setX1TitleString, setX1ZeroLineDisplay

   

>

setY1AxisDescending, setY1AxisLineDisplay, setY1AxisSide, setY1LabelAutofit, setY1LabelDisplay, setY1LabelFormat, setY1LabelStagger, setY1LogScale, setY1MajorGridDisplay, setY1MajorGridStepAuto, setY1MajorGridStyle, setY1MinorGridDisplay, setY1MinorGridStepAuto, setY1MinorGridStyle, setY1MustIncludeZero, setY1OffScaleDisplay, setY1ScaleMax, setY1ScaleMaxAuto, setY1ScaleMin, setY1ScaleMinAuto, setY1TitleDisplay, setY1TitleString, setY1ZeroLineDisplay

   

>

setY2AxisDescending, setY2AxisLineDisplay, setY2AxisSide, setY2LabelAutofit, setY2LabelDisplay, setY2LabelFormat, setY2LabelStagger, setY2LogScale, setY2MajorGridDisplay, setY2MajorGridStepAuto, setY2MajorGridStyle, setY2MinorGridDisplay, setY2MinorGridStepAuto, setY2MinorGridStyle, setY2MustIncludeZero, setY2OffScaleDisplay, setY2ScaleMax, setY2ScaleMaxAuto, setY2ScaleMin, setY2ScaleMinAuto, setY2TitleDisplay, setY2TitleString

 

4.

The following JavaScript data objects are translated by ReadJAVAScriptChartFile():

   

>

getChartBackground

   

>

getCubeFloor, getCubeLeftWall, getCubeRightWall

   

>

getDataText, getFootnote, getFrame, getGroup

   

>

getLegendArea, getLegendLine, getLegendMarker, getLegendText

   

>

getO1MajorGrid, getO2MajorGrid, getO1Label, getO2Axis

   

>

getPieLabel

   

>

getQuadrantLine

   

>

getSeries

   

>

getSubtitle, getTitle

   

>

getX1Title, getY1Axis, getY1Label, getY1MajorGrid, getY1Title

   

>

getY2Label, getY2Title

Also See:

WriteJAVAScriptChartFile()

   

WriteJAVAScriptChartFile()

 

This function saves a graph as JavaScript code that is compatible with the Three |D| Graphics Perspective for Java product. This function can be used to save a chart from the PGSDK into a JavaScript file. This JavaScript file can be loaded in Perspective for Java with or without Chart Data. An option is present to output a JavaScript file as an HTML file to be viewed by a network browser.

Syntax:

PUBLIC INT16
WriteJAVAScriptChartFile(
     GraphPtr pGraph,
     char * pszOutFullPathName,
     BOOLEAN bExportData,
     BOOLEAN bOutputAsHTML
);

Input:

pGraph: Pointer to the graph object created by AllocGraphPtr()

 

pszOutFullPathName; Full path name identifying the name and location of the Java script file to write.

 

bExportData; True/False flag to export data or just the graph "Look".

 

TRUE =

Export Data and Graph

 

FALSE =

Export graph only

 

This flag is normally turned off (FALSE) since the "Look" of the graph is most important. Data is denoted by any of the following.

 

>

Title, SubTitle, Footnote

 

>

Y1Title, Y2Title, X1Title

 

>

SeriesGroupLabels

 

>

Data (example, setData(0,1,2.6) where 0 is the series and 1 is the group and 2.6 is the value.)

 

>

DataRange

 

bOutputAsHTML; True/False

 

TRUE =

Output in HTML format with Header/Trailer

 

FALSE =

Output in Java script format only

 

This flag is useful to save a chart into an HTML file to be viewed by a network browser such as Netscape Navigator or Internet Explorer. Note that Perspective for Java must be setup correctly in the directory where the HTML file exists in order for a chart to properly load.

Return:

INT16;

 

kWRITEJAVASCRIPTFILE_ERRORNONE

0

Success

 

kWRITEJAVASCRIPTFILE_ERROROPENINGFILE

100

Error opening file

 

kWRITEJAVASCRIPTFILE_ERRORFEATURENOTENABLED

200

Feature not enabled

 

kREADJAVASCRIPTFILE_ERRORFEATURENOTENABLED indicates the current version of PGSDK does not support the Read/Write to JAVA script feature. This feature is enabled based on specific customer request. Contact Three |D| Graphics for details.

Example:

int CGraph::TestJavaScriptExporter(
     CDC * pDC, CDrawEnv * pDE)
{
     //Setup a file dialog to save the JAVAScript File
     CFileDialog dlgSave(FALSE, "*.txt");
     dlgSave.m_ofn.Flags |= OFN_HIDEREADONLY |
          OFN_FILEMUSTEXIST; // Set flags
     CString fileName;
     // Setup return pathname
     dlgSave.m_ofn.lpstrFile =           fileName.GetBuffer(_MAX_PATH);
     if(dlgSave.DoModal() == IDOK)
     {
          // Create tmp str to pass to DGDS routine
          fileName = dlgSave.GetPathName();
          LPTSTR lpszFileName = new                TCHAR[fileName.GetLength()+1];
          _tcscpy(lpszFileName, fileName);
          // Write to JAVAScript File
          ::WriteJAVAScriptChartFile((GraphPtr)
               m_pGraph, lpszFileName, 1, 0);
          // Create HTML File string by changing
          // extension to .htm
          size_t nStrLen = strlen(lpszFileName);
          lpszFileName[nStrLen-3] = 'h';
          lpszFileName[nStrLen-2] = 't';
          lpszFileName[nStrLen-1] = 'm';
          // Write chart to HTML File
          ::WriteJAVAScriptChartFile((GraphPtr)
               m_pGraph, lpszFileName, 1, 1);
          delete lpszFileName; // Delete tmp string
     }
     return (0); //no error code determined yet
}

 

The following Perspective for Java functions are an example output of an area chart from this function with bExportData enabled:

 

setGraphType(32);
setDepthAngle(45);
setDepthRadius(10);
setLegendDisplay(true);
setLegendRect(new Rectangle(8653,-3756,7347,7906));
setTransparentFillColor(getLegendArea(),true);
setFillColor(getLegendLine(),new Color(0,254,63));
setFontSizeVC(getLegendText(), 1365);
setFontStyle(getLegendText(), 0);
setFrameDisplay(true);
setRect(getFrame(),new Rectangle(
     -12513,-13235,22024,28735));
setTransparentFillColor(getFrame(),true);
setLineWidth(getFrame(), 0);
setTransparentFillColor(getChartBackground(),true);
setLineWidth(getChartBackground(), 0);
setFillColor(getSeries(0),new Color(254,0,0));
setFillColor(getSeries(1),new Color(0,254,0));
setFillColor(getSeries(2),new Color(0,0,254));
setFillColor(getSeries(3),new Color(254,254,0));
setColorMode(0);
setSeriesAreRows(true);
setReverseSeries(false);
setAxisAssignment(0, 0);
setAxisAssignment(0, 1);
setAxisAssignment(1, 2);
setAxisAssignment(1, 3);
setDataTextDisplay(false);
setDataTextPosition(1);
setDataTextFormat(0);
setFontSizeVC(getDataText(), 1137);
setFillColor(getDataText(),new Color(0,0,0));
setFontName(getDataText(), "Arial");
setX1AxisLineDisplay(true);
setX1LabelDisplay(true);
setX1MajorGridDisplay(true);
setX1MinorGridDisplay(false);
setX1ZeroLineDisplay(false);
setX1AxisSide(0);
setX1AxisDescending(false);
setX1MustIncludeZero(true);
setFillColor(getO1Label(),new Color(0,0,0));
setX1LabelFormat(1);
setX1LabelStagger(false);
setY1AxisSide(0);
setY1AxisLineDisplay(true);
setY1LabelDisplay(true);
setY1MajorGridDisplay(true);
setY1MinorGridDisplay(false);
setY1AxisDescending(false);
setY1MustIncludeZero(true);
setY1ZeroLineDisplay(false);
setFillColor(getY1Label(),new Color(0,0,0));
setY1LabelFormat(1);
setY1LabelStagger(false);
setY2AxisLineDisplay(true);
setY2LabelDisplay(true);
setY2MajorGridDisplay(true);
setY2MinorGridDisplay(true);
setY2MustIncludeZero(true);
setY2AxisDescending(false);
setY2LogScale(false);
setY2AxisSide(1);
setY2LabelFormat(1);
setY2LabelStagger(false);
setFillColor(getY2Label(),new Color(0,0,0));
setO1AxisLineDisplay(true);
setO1LabelDisplay(true);
setO1MajorGridDisplay(true);
setO1MinorGridDisplay(true);
setO1AxisSide(0);
setO1LabelStagger(false);
setO2LabelDisplay(true);
setDisplay(getQuadrantLine(),false);
setQuadrantLineValueX(0);
setQuadrantLineValueY(0);
setRiserBarGroupSpacing(0);
setRiserWidth(60);
setDisplayBarAsPictograph(false);
setRiser3DThicknessY(0);
setAutofit(getDataText(),false);
setO1LabelAutofit(false);
setO2LabelAutofit(false);
setX1LabelAutofit(false);
setY1LabelAutofit(false);
setY2LabelAutofit(false);
setLegendAutomatic(false);
setAutofit(getPieLabel(),true);
setPieDepth(15);
setPieRotate(90);
setPieRingTotalDisplay(true);
setPieRingTotalFormat(1);
setPieRingSize(70);
setPiesPerRow(2);
setPieTilt(40);
setStockOpenTicksDisplay(true);
setStockCloseTicksDisplay(true);
setDisplay3DFloor(true);
setFillColor(getCubeFloor(),new Color(191,191,191));
setDisplay3DLeftWall(true);
setFillColor(getCubeLeftWall(),new Color(191,191,191));
setDisplay3DRightWall(true);
setFillColor(getCubeRightWall(),new Color(191,191,191));
setMarkerShape(true);
setSquareMarkers(true);
setX1LogScale(false);
setY1LogScale(false);
setX1ScaleMinAuto(true);
setX1ScaleMaxAuto(true);
setY1ScaleMinAuto(true);
setY1ScaleMaxAuto(true);
setY2ScaleMinAuto(true);
setY2ScaleMaxAuto(true);
setScaleFromZero(false);
setY1OffScaleDisplay(false);
setX1OffScaleDisplay(false);
setLineWidth(getO1MajorGrid(), 0);
setY1MajorGridStyle(0);
setY1MajorGridStepAuto(true);
setLineWidth(getY1MajorGrid(), 0);
setY2MajorGridStyle(0);
setY2MajorGridStepAuto(true);
setGrid3DRightWallDisplayX(false);
setGrid3DRightWallDisplayY(true);
setGrid3DLeftWallDisplayY(true);
setGrid3DLeftWallDisplayZ(true);
setGrid3DFloorDisplayX(false);
setGrid3DFloorDisplayZ(false);
setGrid3DRiserDisplayX(false);
setGrid3DRiserDisplayY(false);
setGrid3DRiserDisplayZ(false);
setBorderColor(getO2MajorGrid(),new Color(63,63,63));
setLineWidth(getO2MajorGrid(), 0);
setBorderColor(getY1MajorGrid(),new Color(0,0,0));
setLineWidth(getY1MajorGrid(), 0);
setBorderColor(getO1MajorGrid(),new Color(63,63,63));
setLineWidth(getO1MajorGrid(), 0);
setDualAxisLineDisplay(true);
setTitleString("Chart Title");
setTitleDisplay(false);
setRect(getTitle(),new Rectangle(
     -15500,14152,31000,1348));
setFillColor(getTitle(),new Color(0,0,0));
setFontName(getTitle(), "Arial");
setFontSizeVC(getTitle(), 1137);
setFontStyle(getTitle(), 0);
setSubtitleString("Chart Subtitle");
setSubtitleDisplay(false);
setFontName(getSubtitle(), "Arial");
setRect(getSubtitle(),new Rectangle(-15500,12404,31000,1348));
setFillColor(getSubtitle(),new Color(0,0,0));
setFontSizeVC(getSubtitle(), 1137);
setFontStyle(getSubtitle(), 0);
setFootnoteString("Chart Footnote");
setFootnoteDisplay(false);
setRect(getFootnote(),new Rectangle(
     -15500,-15500,31000,1348));
setFontName(getFootnote(), "Arial");
setFillColor(getFootnote(),new Color(0,0,0));
setFontSizeVC(getFootnote(), 1137);
setFontStyle(getFootnote(), 0);
setY1TitleString("Value Title");
setY1TitleDisplay(false);
setRect(getY1Title(),new Rectangle(
     -18351,-259,4180,1522));
setFillColor(getY1Title(),new Color(79,79,79));
setFontName(getY1Title(), "Arial");
setTextRotation(getY1Title(),1));
setFontSizeVC(getY1Title(), 1137);
setFontStyle(getY1Title(), 0);
setY2TitleString("Vehicles");
setY2TitleDisplay(false);
setY2OffScaleDisplay(false);
setRect(getY2Title(),new Rectangle(14343,84,4102,838));
setFontName(getY2Title(), "Arial");
setFillColor(getY2Title(),new Color(0,0,0));
setFontSizeVC(getY2Title(), 1137);
setTextRotation(getY2Title(),2));
setFontStyle(getY2Title(), 2);
setX1TitleString("Category Title");
setX1TitleDisplay(false);
setRect(getX1Title(),new Rectangle(-2096,-13777,3535,877));
setFillColor(getX1Title(),new Color(0,0,0));
setFontName(getX1Title(), "Arial");
setTextRotation(getX1Title(),0));
setFontSizeVC(getX1Title(), 1137);
setFontStyle(getX1Title(), 0);
setSeriesLabelArray(
     "January","February","March","April");
setGroupLabelArray(
     "First","Second","Third","Fourth","Fifth");
setData(0,0,10582.000000);
setData(0,1,10292.000000);
setData(0,2,10172.000000);
setData(0,3,9988.000000);
setData(0,4,8228.000000);
setData(1,0,10201.000000);
setData(1,1,9566.000000);
setData(1,2,10129.000000);
setData(1,3,10389.000000);
setData(1,4,8821.000000);
setData(2,0,7632.000000);
setData(2,1,7459.000000);
setData(2,2,8238.000000);
setData(2,3,7257.000000);
setData(2,4,5592.000000);
setData(3,0,7854.000000);
setData(3,1,7617.000000);
setData(3,2,7984.000000);
setData(3,3,7609.000000);
setData(3,4,7400.000000);
setDataRange(0,0,3,4);

Notes:

1.

Any changes to InitLook in Perspective.java may affect the functionality of this code. There are basic assumptions of attributes being set to states prior to inporting a file.

 

2.

See the Perspective for Java Programmer's Manual for details about each Attribute and corresponding Javascript "set" function.

 

3.

See the PGSDK-to-JavaScript Cross-Reference in the PGSDK Programmer's Manual for a complete list of PGSDK objects, attributes, and API functions that can be translated to Java script.

Also See:

ReadJAVAScriptChartFile()