XRT/graph FAQ
Resources
How do I override XRT/graph's axis notation with my own labels?
You can customize your own annotation by setting XtNxrtAnnotationMethod to XRT_ANNO_VALUE_LABELS, and specifying string value pairs. The string value string pairs can be specified as array or general format.
How do I control the positioning of the legend?
You can use the XtNxrtGraphX, XtNxrtGraphY, XtNxrtLegendX, and XtNxrtLegendY resources to control exactly where the graph area and legend area are positioned.
How do I make the header area go away?
Set XtNxrtHeaderX and XtNxrtHeaderY to negative values so that the placement of the header will not show up in the window. Or, set XtNxrtHeaderStrings to NULL.
How do I stop the graph from redrawing every time I update some resource?
Try setting XtNxrtRepaint to False, then setting the resources, and then setting XtNxrtRepaint to True again.
How do I specify a color other than black for the axes and their labels in an XRT/graph?
Use XtNxrtGraphForegroundColor.
I have a lot of data sets, and it takes a long time to try to set the data styles for all of them.
Use an array of data styles. For example, to set the data styles for 50 data sets, try:
#define Xcalloc(nelem, elsize) calloc(((nelem) > 0 ? (nelem) : 1), (elsize)) #define NELEM 51 ... { XrtDataStyle **myDS= (XrtDataStyle **) Xcalloc(NELEM + 1, sizeof(XrtDataStyle *)); for(i = 0; i < NELEM; i++) { myDS[i] = (XrtDataStyle *) Xcalloc(1, sizeof(XrtDataStyle)); /* fill in data style here ... */ myDS[i]->lpat = XRT_LPAT_SOLID; myDS[i]->fpat = XRT_FPAT_NONE; myDS[i]->color = "Red"; myDS[i]->width = 1; myDS[i]->point = XRT_POINT_NONE; myDS[i]->pcolor = "Blue"; myDS[i]->psize = 4; } myDS[NELEM] = NULL; /* important! */ XtVaSetValues(graph, XtNxrtDataStyles, myDS, NULL); XrtFreeDataStyles(myDS); }
When I zoom into a graph, I lose the axes. How do I keep them around?
The zoom behavior is configurable. See the 'feedback' demo in $XRTHOME/demo/graph/ to implement the behavior you want. The source code is in $XRTHOME/src/graph/demos/feedback/. By default, the axis bounds are based on the range of the data. You can also implement zooming by setting the axis bounds. The 'feedback' demo demonstrates this.
I am using the XrtSetNthSetLabel() to set several labels. Then I try to set just two labels, and set all the others to NULL. Why do the labels I set to NULL still show up?
XrtSetNthSetLabel() ignores requests to set a label to NULL. Try using XtVaSetValues() instead.
Can I sort my data?
Yes, use XrtDataSort(). This function is in the library, but we also provide you the source in:
$XRTHOME/src/graph/util/xrtdrtns.c.Why do the data styles seem random after the first 7 sets?
There are seven default data styles. If you have more than that, XRT/graph will just keep rotating through those 7 styles. If you've defined your own, you must define them for every data set you have. Custom data styles will not recycle like the default styles.
Why doesn't my combination graph work? I'm using XtNxrtData2...
The default type for XtNxrtType2 is XRT_TYPE_BAR (p.158). So, if you were using general data, the bar chart won't show (p.15). You'll want to either change the graph type or the data type.
How do I draw things (lines, pixmaps, etc.) on top of the graph widget?
You will need to use Xlib functions. The "profile" demo provides a good example of this. The precompiled demo is in $XRTHOME/demo/graph/ and the source is in $XRTHOME/src/graph/demos/profile/. To compile, however, you'll need to install XRT/3d. The Xlib drawing functions are in ntrols.c.
How do I change the XtNxrt[Header|Footer][Height|Width] resource?
You cannot change these resources. They are read only.
Printing XRT/graph
How can I output my graph without displaying it?
XRT/graph must connect to an X server to determine its size and to allocate resources such as fonts and colors. However, the widget does not need to actually draw itself on a screen in order to output itself. Look at:
Creating XRT/graph images for the webIs there a way to print out a graph that will span more than one page?
XRT/graph has no convenience functions that will do this for you, but it can be done. Set the width parameter to a length corresponding to the number of pages you want the graph to print across. eg 17" for 2 pages, 25.5" for 3, etc. Of course, for a tall graph, adjust the height. Then use either x_offset or y_offset, whichever is appropriate, to shift the graph. You are going to have to do this for each section/page of the graph. So for the first page, print with offset=0 (you'll get a graph with the left or bottom cut off).
For the second page, you'll need to set the offset= -n, where n is the width/height of the page. Make sure that the offset is a negative number. It'll be like photographing sections of the graph at a time. Aspect ratios, etc. will require some fine tuning.
Samples and Examples
Pie Charts including text attachment and legend
The following code and data create a simple pie chart. This code also demonstrates how to attach text to the chart and also how to display a legend.
#include <X11/Intrinsic.h> #include <Xm/Xm.h> #include <Xm/XrtGraph.h> int main(int argc, char *argv[]) { XtAppContext app_context; Widget graph, toplevel; XrtData *my_data; XrtTextDesc text; static String textlist[] = { "here", NULL }; static char *set_labels[] = { "aaa", "bbb", "ccc", "ddd", "eee", "fff", NULL}; /* allocate and load the data */ my_data = XrtMakeDataFromFile("pie.dat", NULL); XtSetLanguageProc(NULL, NULL, NULL); toplevel = XtVaAppInitialize(&app_context, "Plot 1", NULL, 0, &argc, argv, NULL, NULL); graph = XtVaCreateManagedWidget("mygraph", xtXrtGraphWidgetClass, toplevel, XtNxrtData, my_data, XtNxrtType, XRT_TYPE_PIE, XtNxrtSetLabels, set_labels, XtNxrtLegendShow, True, XtNxrtPieThresholdMethod, XRT_PIE_SLICE_CUTOFF, XtNxrtPieThresholdValue, XrtFloatToArgVal(10.0), XtNxrtOtherLabel, "other", NULL); text.position.data.type = XRT_TEXT_ATTACH_DATA; text.position.data.dataset = 1; text.position.data.set = XRT_OTHER_SLICE; /* data.point specifies which graph. 0 is the first, 1 is the 2nd */ text.position.data.point = 0; text.strings = textlist; text.anchor = XRT_ANCHOR_HOME; text.offset = 0; text.connected = 0; text.adjust = XRT_ADJUST_RIGHT; text.fore_color = NULL; text.back_color = "Pink"; text.border = XRT_BORDER_SHADOW; text.border_width = 2; text.font = NULL; text.psfont = "Courier-BoldOblique"; (void) XrtTextCreate(graph, &text); free((char *) text.strings); XtRealizeWidget(toplevel); XtAppMainLoop(app_context); } /* Use the following data ("pie.dat"). Note, for two pie graphs, change ARRAY 5 1 to ARRAY 5 2 and add another column of data.*/ ARRAY 5 1 # x values -- not used 1.0 # slice values - percentage 20.0 15.0 40.0 16.0 9.0
Errors, Warnings, Seg Faults
The graph widget seems to be looking for a font that doesn't exist.
Our fallback is XmFontList, which is supposed to give the default font for the system. However, it appears that it doesn't do that in all cases. All you should really need to do is add the following to your resource file:
*.XtXrtGraph.FontList: my-favorite-fontlist-that-I-know-will-always-be-there
I get a core dump when my application starts.
One of the most common mistakes is forgetting to use XrtFloatToArgVal() with floating point resources.
What does the error 'Unexpected symbol '#' in XrtGraph.hxx' mean?
This error is because your compiler does not support the new style of token pasting macros. i.e. ##. Instead it expects token pasting to use /**/. The XrtGraph.hxx header file does try to catch all the possible cases where you would have an older compiler, but it can't catch them all. To solve this problem, you will have to edit the file XrtGraph.hxx and change the ## characters to /**/.