13 Working with Charts

impulse charts build a new dimension of displaying signals and signal-related information. Charts can be extended and configured in many ways. You can define your own charts or integrate existing chart tools.

Charts is an extended feature (versions >= 1.1)

Steps to define a chart

On opening the preferences pages of impulse, you will find the chart settings. This is the place where all charts are defined and configured. You can use the impulse wallet to exchange charts and other configurations with your colleagues. Here are the basic steps to get a chart displayed..

  1. Get to chart preferences and create/ configure a chart.
  2. Select a signal of a type that is compatible with the intended chart, or
  3. Prepare a signal script to set-up the chart data
  4. Open the configuration editor (in the viewer) and select your chart.

The type of signal that is required for a chart depends on the chart type and configuration (see below).

For your first experiments with charts, you may use this wave file: charts.recJs

Birt chart provider

The Birt chart provider uses the chart implementation of the Eclipse BIRT project.

Types and Options

This provider has Bar, Pie, Line and Radar charts. The provider supports the Birt script extension mechanism (see the book "Integrating and Extending BIRT").

Compatible data

The birt chart provider accepts float, integer, events (with enumerations) and struct signals. Struct signals are usually the best choice for birt charts. The member names (of integer and float members) represent the category values. An addtitional "LABEL" member carries the series label.

Signal script to define chart data

Use the following signal script example to prepare chart data using a struct signal.

  // members
  var members  = out.createMembers(7);
  out.createMember(members,0,"A",	IStructSample.STRUCT_TYPE_INTEGER,null,-1);
  out.createMember(members,1,"B",	IStructSample.STRUCT_TYPE_INTEGER,null,-1);
  out.createMember(members,2,"C",	IStructSample.STRUCT_TYPE_INTEGER,null,-1);
  out.createMember(members,3,"D",	IStructSample.STRUCT_TYPE_INTEGER,null,-1);
  out.createMember(members,4,"E",	IStructSample.STRUCT_TYPE_INTEGER,null,-1);
  out.createMember(members,5,"G",	IStructSample.STRUCT_TYPE_INTEGER,null,-1);
  out.createMember(members,6,"Label",	IStructSample.STRUCT_TYPE_TEXT,"LABEL",-1);
  
  // Series 1
  members[0].setIntValue(12);
  members[1].setIntValue(12);
  members[2].setIntValue(12);
  members[3].setIntValue(12);
  members[4].setIntValue(12);
  members[5].setIntValue(12);
  members[6].setStringValue("Series 1"); 
  out.write(0,false,members);

  // Series 2
  members[0].setIntValue(14);
  members[1].setIntValue(15);
  members[2].setIntValue(16);
  members[3].setIntValue(17);
  members[4].setIntValue(18);
  members[5].setIntValue(19);
  members[6].setStringValue("Series 2");
  out.write(1,false,members);

Nebula chart provider

The Nebula chart provider uses the chart implemenentation of the Eclipse Nebula/Visualization project.

Types and Options

XY and Intensitivy chart. Both charts can be extended using js scripts.

Compatible data

The XY chart accepts float signals with dimensions 1 and 2 (XY). You can disable the default chart data provider ("Manual fill"). The intensity chart has no default chart data provider.

Intensity chart script example

Use the following chart script example to prepare an intensity chart.

  // configure axes
  graph.getXAxis().setAutoScale(false);
  graph.getXAxis().setTitle("myX");
  graph.getYAxis().setAutoScale(false);
  graph.getYAxis().setTitle("myY");      
  graph.getYAxis().setRange(-50, 50, false);
  
  // configure data
  graph.setMax(100);
  graph.setMin(-100);
  var dataHeight = 64;
  var dataWidth = 64;
  graph.setDataHeight(dataHeight);
  graph.setDataWidth(dataHeight);
  
  // create simulation data
  var simuData = java.lang.reflect.Array.newInstance(java.lang.Integer.TYPE, dataWidth * dataHeight * 2);
  var i,j,seed = 0;
  for (i = 0; i < dataHeight; i++) {
      for (j = 0; j < dataWidth; j++) {
          var xn = j - dataWidth;
          var yn = i - dataHeight;
          var p = Math.sqrt(xn * xn + yn * yn);
          simuData[i * dataWidth + j] = Math.sin(p * 2 * Math.PI / dataWidth + seed * Math.PI / 100) * 100;
      }
  }
  graph.setDataArray(simuData);

Script charts

Script charts allow the user to define completely his own chart.

Script chart example

  // gc: graphics context (https://www.eclipse.org/articles/Article-SWT-graphics/SWT_graphics.html)
  // x,y,width,height: geometry
  // color, background: Colors
  // readable: input of IReadableSamples  (http://toem.de/index.php/projects/impulse/scripts/reference)
  
  gc.setForeground(color);
  var count = readable.getCount();
  var first = readable.positionAt(0);
  var last = readable.positionAt(count-1);
  var value0 = readable.valueAt(0);
  var valueN = readable.valueAt(count-1);

  gc.drawText("Count: " +count,x+20,y+20);
  gc.drawText("From: " +first,x+20,y+40);
  gc.drawText("To: " +last,x+20,y+60);
  gc.drawText("Value[0]: " +value0,x+20,y+80);
  gc.drawText("Value[N]: " +valueN,x+20,y+100);
  
  gc.setBackground(color);
  gc.fillRectangle(x+20,y+120,width-40,20);
  gc.setBackground(gc.getDevice().getSystemColor(7));
  gc.fillRectangle(x+20,y+150,width-40,20);
  gc.setBackground(gc.getDevice().getSystemColor(15));
  gc.fillRectangle(x+width - 50,y+20,20,height - 40);
  
  gc.setForeground(color);
  gc.setBackground(background);
  gc.drawText("Impulse Script Chart ",x+20,y+180);