Chart Object Class


Overview

ChartObject provides the view component of the MVC architecture described earlier. To create a chart, the application or the end-user needs to create a Chart object. This object automatically creates a number of sub-objects to compose the plot. For example, the chart may create axes objects, Text objects for annotation, a Legend object, a plot object, series objects, etc.

Inherited Resources and Behavior

The Chart object class inherits behavior and resources from the Xt Object, Graphic and Group object classes.
The following resources are defined by the Chart object class:
NameTypeDefaultAccess
XmNaxisSpacingint10CSG
XmNchartFooterStringNULLCSG
XmNchartMarginsXintChartMargins *{10., 10., 10., 10.}CSG
XmNchartTitlechar *NULLCSG
XmNchartTypeintXintCHART_TYPE_BARCSG
XmNcolorListString *{"red", "green", "blue", "yellow", "violet", "cyan", "salmon", "PaleGreen2", NULL}CSG
XmNdoubleBufferBooleanTrueCSG
XmNgeometryXintGeometry *{ 15, 15, 85, 85}CSG
XmNpropagateBooleanFalseCSG
XmNshowLegendBooleanFalseCSG
XmNsymbolCountintdynamicCSG
XmNsymbolListint *dynamicCSG
XmNtransposeBooleanFalseCSG
XmNzValueColorRecordXintColorRec *NULLCSG


XmNaxisSpacing

Specifies the space to leave between adjacent axes in the horizontal or vertical direction.

XmNchartFooter

Specifies a string that will be used as the Chart footer. If this resource is specified, the Chart object will create and manage a Text object. If you need to customize the appearance of the footer, use function XintChartGetComponent to extract the footer object ID. See constraint resource XmNconstraint to set the position of the footer object.

XmNchartMargins

Specifies the margins for the chart. The margins correspond to the space left between the chart boundaries and the axes (or plot if there is no axis on one side), as a percentage between 0 and 100.

This resource is specified as a pointer to a data structure of type XintChartMargins, which takes the following form:

   typedef struct {
                    int left;
                    int right;
                    int top;
                    int bottom;
   } XintChartMargins;

where:

MemberDescription
leftLeft margin as a percentage between 0 and 100.
rightRight margin as a percentage between 0 and 100.
topTop margin as a pecentage between 0 and 100.
bottomBottom margin as a pecentage between 0 and 100.


XmNchartTitle

Specifies a string that will be used as the Chart title. If this resource is specified, the Chart object will create and manage a Text object. If you need to customize the appearance of the title, use function XintChartGetComponent to extract the title object ID. See constraint resource XmNconstraint, described in the next section, to set the position of the title object.

XmNchartType

Specifies the default chart type. You can specify one of the following constants:

ConstantDescription
XintCHART_TYPE_AREAArea plot.
XintCHART_TYPE_BAR2D Bar plot.
XintCHART_TYPE_BAR_3D3D bars plot.
XintCHART_TYPE_CELL_ARRAY2D array of colored cells.
XintCHART_TYPE_COMBINATIONCombination plot.
XintCHART_TYPE_HIGH_LOWHigh-Low plot.
XintCHART_TYPE_HISTOGRAMHistogram plot.
XintCHART_TYPE_LINELine plot.
XintCHART_TYPE_PIE2D Pie plot.
XintCHART_TYPE_SCATTEREDScattered plot.
XintCHART_TYPE_SURFACE_3D3D Surface plot.


XmNcolorList

Specifies a NULL terminated list of color names (string array) used to assign the data series colors. Colors are assigned sequentially in the list. When the end of the list is reached, it is reset to the beginning. To change the color assigned to a specific series, retrieve the series object ID using function XintChartGetSeriesOfData and use the appropriate resource (usually XmNcolor or XmNfillColor).

XmNdoubleBuffer

Specifies whether or not double buffering is set. The default is True. For Plot3D objects this resource is ignored and double buffering is always set.

XmNgeometry

Specifies the geometry of the chart object in the parent coordinate system.

This resource is specified as a pointer to a data structure of type XintGeometry, which takes the following form:

   typedef struct {
                   float x1;
                   float y1;
                   float x2;
                   float y2;
   } XintGeometry;

where:

MemberDescription
x1,y1Coordinates of the upper left corner of the chart.
x2,y2Coordinates of the lower right corner of the chart.


XmNpropagate

Specifies whether or not to propagate the resources set in a call to XtSetValues to the Chart's sub-objects (Plot, Axes, Legend, etc.). This resource is particularly useful to propagate resources controlling the edit mode such as XmNsensitive, XmNmove or XmNshape. It can also be used to propagate graphic attributes such as the background color or the font. This resource is automatically reset to False after it has been applied.

XmNshowLegend

Specifies whether a legend is displayed. If this resource is set to True, a Legend object is created. If you need to customize the legend, use function XintChartGetComponent to extract the ID of the Legend object.

XmNsymbolCount

Specifies the number of symbols defined in resource XmNsymbolList.

XmNsymbolList

Specifies a list of default symbols used in some plot types such as the scatter plot. The symbols in the list are used in turn (i.e.: the first series that requires a symbol will use the first symbol specified, the second series will used the second symbol, etc.). When the end of the list is reached, it is reset to the first symbol. The size of this array is specified using resource XmNsymbolCount. The symbol list can contain any of the symbol constants listed below:

Symbol ConstantDescription
XintSYMBOL_XX symbol.
XintSYMBOL_PLUS+ symbol.
XintSYMBOL_SQUARESquare symbol.
XintSYMBOL_CIRCLECircle symbol.
XintSYMBOL_TRIANGLETriangle symbol.
XintSYMBOL_DIAMONDDiamond symbol.
XintSYMBOL_FILLED_SQUAREFilled square symbol.
XintSYMBOL_FILLED_CIRCLEFilled circle symbol.
XintSYMBOL_FILLED_TRIANGLEFilled triangle symbol.
XintSYMBOL_FILLED_DIAMONDFilled diamond symbol.


XmNtranspose

This resource controls whether or not to transpose DataSampled series. The transpose functionality is supported by several plot classes, including BarLine, Pie, XYPlot and all the 3D plot classes. See the Data section of each plot class for a description on how it handles transposed data.

XmNzValueColorRecord

Specifies a pointer to an opaque structure containing a list of color pixels that are used to display plot types that color their data series based on a Z value (or Y for 2D plots), including Surface3D, Bar3D and BarLine. If this resource is not specified, the colors specified using resource XmNcolorList will be used. See Chart function XintChartCreateColorRecord to create a color record structure from an array of pixel values.

Constraint Resources

The position of the Chart sub-objects is managed by the Chart. For example, the Chart normally will position the title above the Plot object and the legend to the right of the Plot object. Constraint resource XmNconstraint can be used to override the default placement of objects managed by the Chart, including any external objects inserted by the application. This resources does not apply to Plot objects, whose geometry is controlled by Chart resource XmNchartMargins. Resource XmNconstraint is specified using a pointer to a union of type XintConstraint which takes the following form:

   typedef union  {
                   struct { 
                            int type;
                            int anchor;
                   } placement;
   } XintConstraint;

Member type should always be set to XintCONSTRAIN_PLACEMENT. For member anchor, use one of the following constants:

Defined ConstantsDescription
XintANCHOR_NORTHObject placed above the Plot.
XintANCHOR_NORTH_EASTObject placed next to the upper right corner of the Plot.
XintANCHOR_NORTH_WESTObject placed next to the upper left corner of the Plot.
XintANCHOR_SOUTHObject placed below the Plot.
XintANCHOR_SOUTH_EASTObject placed next to the lower right corner of the Plot.
XintANCHOR_SOUTH_WESTObject placed next to the lower left corner of the Plot.
XintANCHOR_EASTObject placed right of the Plot.
XintANCHOR_WESTObject placed left of the Plot.
XintANCHOR_CENTERObject placed at the center inside the Plot.

The following code sample shows how to position the title at the bottom of the plot.

   Object chart;
   Object title;
   XintConstraint constraint;
   ...
   title = XintChartGetComponent(chart, XintCHART_COMPONENT_TITLE);
   constraint.placement.type = XintCONSTRAIN_PLACEMENT;
   constraint.placement.anchor = XintANCHOR_SOUTH;
   XtVaSetValues((Object) title, XmNconstraint, &constraint, NULL);

You can also use resource XmNconstraint to specify the placement of objects created by the application and inserted into the Chart using function XintChartInsertObject. If XmNconstraint is left NULL, the object will be positioned based on its own geometry resource, using the Chart coordinate system (0 to 100 in both directions with the origin located in the upper left corner).


Chart Callbacks

The Chart object class does not define any new callbacks. However, the callback structure returned with callback XmNverifyCallback (see class Graphic) is redefined. The ollowing ordered table lists the members of the callback structure XintChartVerifyCallbackStruct:

Data TypeMemberDescription
intreasonIndicates why the callback was invoked (XintCR_NEW_CHART_TYPE, XintCR_OBJECT_MOVE or XintCR_OBJECT_SHAPE).
XEvent *eventPoints to the XEvent that triggered the callback.
XintGeometry *proposedProposed geometry for move or shape operations.
intold_chart_typeOld chart type (for reason XintCR_NEW_CHART_TYPE).
intnew_chart_typeNew chart type (for reason XintCR_NEW_CHART_TYPE)
BooleandoitSet to False to cancel the operation.


Functions

The following functions are defined for creating, updating or retrieving information regarding a particular Chart object.

Function NameDescription
XintCreateChartCreates a Chart object.
XintChartAssociateDataAssociates data with a chart.
XintChartCreateColorRecordCreates a color record.
XintChartDisassociateAllDataDisassociates all data associated to a chart.
XintChartDisassociateDataDisassociates data from a chart.
XintChartFreezeUpdatesTo freeze (or unfreeze) the chart while doing a series of changes.
XintChartGetComponentReturns a particular component of the Chart.
XintChartGetDataListReturns the list of all the data groups that are connected to the specified Chart.
XintChartGetDataOfSeriesReturns the data object associated to the specifed series in a Chart.
XintChartGetSelectedComponentReturns the selected component inside a chart.
XintChartGetSeriesOfDataReturns the object series of a Chart associated with the specified data element.
XintChartInitializeClassConverterInitializes the ChartObject class converter.
XintChartInsertObjectTo insert a user defined object inside a chart or a plot.
XintChartIsTransposedTo tell if a Chart is transposed or not.
XintChartPickTo implement picking or data selection.
XintChartReadTemplateReads a list of Chart templates from a disk file.
XintChartSaveTemplateSaves a list of Chart templates in a disk file.
XintChartZoomTo zoom a Chart object.


XintCreateChart

This function creates a chart object and defines all the resources for it.

     Object XintCreateChart (...)

WidgetparentParent of new chart object.
char *nameName of new chart object.
ArgListarglistList of resource settings for th e new chart.
CardinalargcountNumber of resources set by arglist.


XintChartAssociateData

This function associates a data group or a data item with a chart object. If you want multiple data group objects associated with a specified chart, you can call this function repeatedly.

     void XintChartAssociateData (...)

ObjectchartID of the chart object.
ObjectdataID of the data group or data object to associate with the chart.


XintChartCreateColorRecord

This function creates a color record from an array of pixels that has been allocated by the application. A color record is a pointer to an opaque structure, XintColorRec, that can be used to specify Chart resource XmNzValueColorRecord.

     XintColorRec *XintChartCreateColorRecord (...)

Pixel *pixelsArray of pixels that has been allocated by the application.
intpixel_countNumber of pixels in array pixels.


XintChartDisassociateAllData

This function disassociates all data from a chart object.

     void XintChartDisassociateAllData (Object chart)


XintChartDisassociateData

This function disassociates a data group or a data item from a chart object. This function returns False if the data group or data item was not previously associated with the chart.

     void XintChartDisassociateData (...)

ObjectchartID of the chart object.
ObjectdataID of the data object or data group to disassociate from the chart.


XintChartFreezeUpdates

Specifies whether to freeze or unfreeze a chart.

     Boolean XintChartFreezeUpdates (...)

ObjectobjectObject ID of the chart to be frozen.
inttoggleSet to 1 to freeze; 0 to unfreeze.

If toggle is set to freeze chart and the chart is already frozen th en it returns False. If toggle is set to unfreeze chart and the ch art is not frozen then it returns False. Otherwise, it returns True.


XintChartGetComponent

This function returns the object ID of a specified component of the chart.

     Object XintChartGetComponent (...)

ObjectchartID of the chart object.
intcodeCode of the component to return.

The argument code can be one of the following constants:

ConstantDescription
XintCHART_COMPONENT_PLOTThe code for the plot object.
XintCHART_COMPONENT_VERTICAL_AXISThe code for the vertical axis object.
XintCHART_COMPONENT_HORIZONTAL_AXISThe code for the horizontal axis object.
XintCHART_COMPONENT_LEGENDThe code for the legend object.
XintCHART_COMPONENT_TITLEThe code for the title object.
XintCHART_COMPONENT_FOOTERThe code for the footer object.


XintChartGetDataList

This function returns the list of all the data groups or data items that have been associated with a particular Chart object using function XintChartAssociateData.

     Object *XintChartGetDataList (...)

ObjectchartChart object ID.
int *countReturns the data group count.

If the list returned is not NULL, you should free it after it is no longer needed.


XintChartGetDataOfSeries

This function returns the list of data objects that are associated with the specified series component of a Chart. Most series represent one single data object component. Some series, like a HighLow series or a surface, represent more than one data object. Also, when a Chart is transposed (Chart resource XmNtranspose set to True) multiple series can be used to represent a data object.

     Object *XintChartGetDataOfSeries (...)

Objectchart_or_plotChart or Plot object ID.
ObjectseriesID of the series element.
int *count Returns the number of data objects associated with series.

You will need to free the object list returned after it is no longer needed.


XintChartGetSelectedComponent

When a chart or an object inside a chart is selected, the EditObject selection callback structure and function XintEditObjectSelectList always return the ID of the chart object. This convenience function can be used to retrieve the ID of the sub-component of the chart that was selected. It also returns a code indicating the type of the selected component.

     Object XintChartGetSelectedComponent (...)

ObjectchartID of the chart object.
int*codeCode for the returned component.

The argument code will be one of the following constants:

ConstantDescription
XintCHART_COMPONENT_CHARTSelected object is the chart.
XintCHART_COMPONENT_PLOTSelected object is the plot.
XintCHART_COMPONENT_VERTICAL_AXISSelected objet is the vertical axis.
XintCHART_COMPONENT_HORIZONTAL_AXISSelected object is the horizontal axis.
XintCHART_COMPONENT_LEGENDSelected object is the legend object.
XintCHART_COMPONENT_TITLESelected object is the title object.
XintCHART_COMPONENT_FOOTERSelected object is the footer object.
XintCHART_COMPONENT_SERIESSelected object is a series.
XintCHART_COMPONENT_USER_OBJECTSelected object is an object that was inserted using XintChartInsertObject.


XintChartGetSeriesOfData

This function returns the list of object series used to represent a particular data element that is part of a Data Group associated with the chart. For most chart types, a single series object is used to represent a data object. For example, a DataSampled object is displayed using a BarSeries in a bar chart. If the Chart object is transposed (resource XmNtranspose set to True) and argument data is a DataSampled object, multiple series may be returned.

     Object *XintChartGetSeriesOfData (...)

Objectchart_or_plot Chart or Plot object ID.
ObjectdataID of the data element.
int *countReturns the number of series elements associated with data.

You will need to free the object list returned after it is no longer needed.


XintChartInitializeClassConverter

This function is used to install the ChartObject class converter. This converte r is used to convert the ascii object format and templates for the ChartObject f rom the string class name to the widget pointer class.

     void XintChartInitializeClassConverter (void)


XintChartInsertObject

This function allows the insertion of a graphic object, created by the application, inside a Chart or Plot2D object. User defined objects cannot be inserted inside a Plot3D object. If the object is inserted inside a Chart, its coordinate system is the Chart coordinate system which is between 0 and 100 in both the vertical and horizontal directions. If the object is inserted inside a Plot2D, the coordinate system is the one defined by the axes attached to the Plot2D object.

     void XintChartInsertObject(...)

Objectchart_or_plotID of the Chart or the Plot in which to insert the object.
ObjectobjectID of the object to be inserted.


XintChartReadTemplate

This function reads a template file that was created by the XintChartSaveTemplate function and restores the Chart or Charts that were saved in template form. Each Chart is associated with a data group by this function. However, the data are not required to be defined as formal DataGroup objects; any of the INT data object classes may be used. A list of the restored Charts is returned.

     Object *XintChartReadTemplate (...)

WidgetparentWidget ID of the parent of this Chart object.
char *filenameName of the file that contains the Chart templates.
Object *data_group_listList of data groups, one per Chart from the template file.
intdata_group_countNumber of data groups in the list.
int *countReturns the number of Chart objects read from disk and restored.


XintChartSaveTemplate

This function saves the listed Chart objects (and related objects) into a disk file. The Chart objects are saved in template format, meaning that the visual attributes of an object are saved, but the data associated with the object are not saved. This permits a Chart object to be read from disk by the XintChartReadTemplate function and used to display new data. Other, non-Chart, objects are entirely saved, including their data. All of the objects in the object_list must have the same parent.

     Boolean XintChartSaveTemplate (...)

char *filenameName of the file where the Chart object templates will be stored.
Object *object_listList of Chart and non-Chart objects to be saved on disk in template format.
intcountNumber of objects in the list.

The function will return False if it cannot write to the specified file; otherwise it will return True.


XintChartIsTransposed

This convenience function returns True if resource XmNtransposed is True and False otherwise.

     Boolean XintChartIsTransposed (Object chart)


XintChartPick

This function can be used to implement picking or data selection. Function XintChartPick converts an (X,Y) location inside a plot, specified as an event structure, into the corresponding data object and point index. If the location selected is outside the plot boundary or no data is selected, then the function returns NULL. Most applications requiring picking should use EditObject callback XmNselectionCallback and call XintChartPick inside the callback routine. This function only works for 2D chart types.

     Object XintChartPick (...)

Widgetedit_objectID of the EditObject Widget.
XEvent *eventEvent to process (must be a button event of type ButtonPress or ButtonRelease).
int*indexReturns the index of the data point selected.


XintChartZoom

This convenience function can be used to zoom a Chart object. The application must specify a rectangle in pixel coordinates defining the area to zoom. The Chart object viewport will be changed so that it displays only the intersection of the plot area with the specified rectangle. This function is normally called from a callback procedure attached to callback XmNareaSelectionCallback (see EditObject Reference section). The geometry of the selected rectangle is provided inside the callback structure. The function returns NULL and does not change the Chart object if the selected rectangle does not intersect with the plot area.

     Boolean XintChartZoom (...)

ObjectchartID of the Chart object to Zoom.
intx,yPixel coordinates of the upper left corner of the area to zoom.
intwidth, heightSize in pixels of the area to zoom.


Macros

Macro XintIsChart returns True if the specified object is a Chart object and False otherwise.

     Boolean XintIsChart (Object object)