ChartObject WebFAQ - Q14




#include &ltXint/Chart.h>
#include &ltXint/EditObject.h>

float    labels_p[] = {10, 20, 30, 40};
float    d1992[] = { 00.0, 30.0, 20.0, 20.0};
Object   data_group;
Widget        top_level;
Widget        edit;
Object        chart, *line;
String        str_array[4];
char          buffer[4][256];
Object        data_label;

static char my_translations[] =
"None &ltBtn1Up>: EndAreaSelection() ObjectEditEnd() my_action()";
XtTranslations my_translations_parsed;

static void
my_action(Widget widget, XEvent *event, String *params, int *num_params)
{
  int   i;
  float *position;
  Object  data_series;

 /* Add some batch and chart freeze API functions to decreas CPU time */
  XintDataBatchUpdate(data_group, True);
  data_label = XintDataListIterate(&data_group, 1,
                                        xintDataLabelObjectClass, 0);


  data_series = XintDataListIterate(&data_group, 1, xintDataSeriesObjectClass, 0);
  position = XintDataSeriesGetXArray(data_series, 0, 4);
  for(i = 0; i < 4; i++){
     sprintf(buffer[i], "%3.1f", position[i]);
     str_array[i] = buffer[i];
  }
  XintDataLabelShift(data_label, str_array, position, 4);
  XintDataBatchUpdate(data_group, False);

}
static XtActionsRec app_actions[] = {
   {"my_action", (XtActionProc) my_action}
};


main(argc, argv)
  int     argc;
  char    *argv[];
{
  XtAppContext  app_context;
  XintGeometry  chart_geometry;
  int           i, count;

  top_level  = XtAppInitialize(&app_context, "test",
				(XrmOptionDescList)NULL, 0,
				&argc, argv, NULL, NULL, 0);
  XtAppAddActions(app_context, app_actions, XtNumber(app_actions));

 /*
  * Parse translations
  */
  my_translations_parsed = XtParseTranslationTable(my_translations);



   /* Create an EditObject widget*/

   edit = XtVaCreateManagedWidget("edit_object", 
	xintEditObjectWidgetClass,top_level,
	XmNwidth, 600, XmNheight, 600,
	XmNobjectEditMode, XintEDIT_ADJUST,
	NULL);
  XtOverrideTranslations(edit, my_translations_parsed);


   /* Create Chart object */

    chart_geometry.x1 = 0;
    chart_geometry.y1 = 0;
    chart_geometry.x2 = 100;
    chart_geometry.y2 = 100;
    chart = (Object) XtVaCreateWidget("BarPlot",
                                (WidgetClass)xintChartObjectClass, edit,
                                XmNgeometry, &chart_geometry,
                                XmNchartType, XintCHART_TYPE_LINE,
                                XmNchartTitle, "Yearly Sales",
                                XmNshowLegend, True,
                                NULL);

    /* Create a data group */

    data_group = XintCreateDataGroup(edit, "Yearly Sales", NULL, 0);

    for(i = 0; i < 4; i++){
     sprintf(buffer[i], "%3.1f", labels_p[i]);
     str_array[i] = buffer[i];
     }

    XtVaCreateWidget("Cities", (WidgetClass)xintDataLabelObjectClass, 
                     edit,
                     XmNlabelStrings, str_array,
                     XmNlabelPositionArray, labels_p,
                     XmNlabelCount, sizeof(labels_p)/sizeof(float),
                     XmNlabelOrientation, XintLABEL_X,
                     XmNdataGroup, data_group, NULL);

    XtVaCreateWidget("1992", (WidgetClass)xintDataSeriesObjectClass, 
                     edit,
                     XmNyArray, d1992,
                     XmNxArray, labels_p,
                     XmNeditable, True,
                     XmNcount, sizeof(d1992)/sizeof(float),
                     XmNdataType, XintDATA_TYPE_FLOAT,
                     XmNdataGroup, data_group, NULL);


    /* Associate the data group with the chart object */

    XintChartAssociateData(chart, data_group);

 
    line = XintChartGetSeriesOfData(chart, data_group, &count);
    XtVaSetValues((Widget) *line,
                   XmNmoveDirection, XintMOVE_HORIZONTAL, NULL);
    free(line);

    /* Loop forever */

    XtRealizeWidget(top_level);
    XtAppMainLoop(app_context);
}

Back to ChartObject FAQ

© INT 1996.
x 8"../../gifs/gif/button.return.gif">Back to ChartObject FAQ

© INT 1996.