2D Charts

  1. Bar charts
  2. Customizing charts using the mouse
  3. Pareto charts
  4. Box-and-Whiskers charts
  5. XY charts
  6. Pie charts

Bar charts

First, create a data matrix containing names in its first column, and the corresponding values in its second column. Then, use the barchart function.

An example data matrix is:


a=("Jessica", 45 ; "Jim", 150 ; "Janine", 15 ; "Jay", 52 ; "Jerry", 65)
"Jessica"  45
"Jim"     150
"Janine"   15
"Jay"      52
"Jerry"    65

A bar chart with this data is found by entering:


barchart(a)

Figure 1. below shows the resulting chart.


Figure 1. Simple barchart

Function barchart has several optional ways to personalize your chart. To add a title use the "title:text" option.


barchart( a, "title:Funny J People" )

Figure 2. Barchart with title

For a complete list of optional parameters, click the icon below.

Labels can be easily added as shown in the line below. Also, the "horizontal" option is used to swap the axis of the chart.


barchart( a, "title:Funny J People", "labels:Name:Ranking", "horizontal" )

Figure 3. Adding labels and swapping the chart.

Custom colors can be specified in a third column of the data matrix. Notice you may use predefined names or_ you may specify the colors using hexadecimal values.


a = ("Jessica", 45, "#5588aa" ; "Jim", 150, "#ff9999" ; "Janine", 15, "#7777ff" ; "Jay", 52, "#aa2288" ; "Jerry", 65, "gray" )
 "Jessica"  45  "#5588aa"
 "Jim"     150  "#ff9999"
 "Janine"   15  "#7777ff"
 "Jay"      52  "#aa2288"
 "Jerry"    65  "gray"

The color of the background and the color of the grid lines can also be specified. To remove the grid lines, use option "nogrid".

Example:


barchart(a, "title:Funny J People", "labels:Name:Ranking", "background:#ddeeff", "grid:white" )

Figure 4. Barchart with personalized colors

By default, the names are displayed aligned with the bars. Using the option "uselegend", names are displayed horizontally and a legend is used whenever the names do not fit in the chart.

Example:


barchart(a, "title:Funny J People", "labels:Name:Ranking", "background:#ddeeff", "grid:white", "uselegend" )

Figure 5. Barchart with names displayed horizontally

If you need to sort the values, you may use the "sort" option. To specify the initial tick mark and their spacing use option "tickmarks:init_value:spacing", where both init_value and spacing are integers.

Example:


barchart(a, "title:Funny J People", "labels:Name:Ranking", "background:white", "uselegend", "sort", "tickmarks:5:25" )

Figure 6. Barchart with sorted values and custom tickmarks.

Other options.

Option "cumulative" draws a cumulative line indicating percents. However, this option will be ignored if there is a negative data value.

Option "absolute" plots negative values as positive.

Customizing charts using the mouse

All charts can be customized using the mouse.

Keeping the Z key down and then dragging the mouse, zooms the chart.

Keeping the P key down and then dragging the mouse, pans (translates) the chart.

Keeping the S key down and then dragging the mouse, selects a region for zooming.

Mouse support has been provided because you may capture the charts and further enhance them using third party software. Figure 7. below shows the graph above customized using the mouse.


Figure 7. Customized chart using the mouse.

Pareto charts

Pareto charts are a special type of bar charts in which all values are sorted, negative values are displayed as positive, and only two colors are used; one for positive values and the other for negative values.

Let's create a new data matrix:


a=("January", 20 ; "February", 5 ; "March", -7 ; "May", 14 )
"January"   20
"February"   5
"March"     -7
"May"       14

A Pareto chart with this data is found as follows:


pareto(a)

Figure 8. below displays the resulting chart and the default colors.


Figure 8. Pareto chart.

To change the default color for positive values, use a color name as an option. Use option "negative:color" to specify the color for negative values. The example below uses green for positive values, a light green for negative value, and even a lighter green for the background.


pareto(a ,"green", "negative:#aaffaa", "background:#eeffee")

For a complete list of optional parameters, click the icon below.


Figure 9. Pareto chart with custom colors.

If you need to show cumulative values, use the "cumulative" option as follows:


pareto(a ,"green", "negative:#aaffaa", "background:#eeffee", "cumulative")

Figure 10. Pareto chart with cumulative values.

All of the optional parameters presented for bar charts, apply for Pareto charts too, e.g. "uselegend", "nogrid", "grid:color", etc.

Pareto charts can also be customized using the mouse. See available keys above.

Box-and-Whiskers charts

To prepare a box-and-whiskers chart, create a matrix with 3 to 6 columns of data. The first column must contain names.

The content of the other columns is summarized below:

Example:


a=( "Sales", 45, 50, 55, 70, 90 ; "Costs", 40, 45, 60, 75, 80)
"Sales"  45  50  55  70  90
"Costs"  40  45  60  75  80

A box-and-whiskers chart is obtained using function boxwhiskers as shown below.


boxwhiskers(a)

Figure 11. Box-and-whiskers chart.

Box-and-whiskers charts have the same options as bar charts and pareto charts. For example, you may customize the chart above as follows:


boxwhiskers(a,"title:Sales vs. Costs", "labels: :Millions", "background:black", "white", "grid:lightGray", "tickmarks:0:10", "horizontal")

Figure 12. Customized box-and-whiskers chart.

For a complete list of optional parameters, click the icon below.

Box-and-whiskers charts can also be customized using the mouse. See available keys above.

XY charts

To plot x-y pairs of values, create a data matrix with its first column containing the x values, and the second column containing the y values. Then, use function xychart.

Example:

First we create some data.


a=( 1, 3 ; 3, 1 ; 5, 7 ; 8, 7 ; 10, 14 ; 12, 12 )
 1   3
 3   1
 5   7
 8   7
10  14
12  12
b=( 1, 5 ; 3, 3 ; 5, 15 ; 8, 13 ; 10, 15 ; 12, 17)
 1   5
 3   3
 5  15
 8  13
10  15
12  17

To plot the first set do:


xychart(a)

To add the second set in red, do:


xychart(b, "red")

Figure 13 below shows the resulting chart.


Figure 13. XY-chart.

For a complete list of optional parameters, click the icon below.

In addition to specifying a color, several decorations are available. You may use options "circle", "rhombus", "square", "triangle", "vertical" and "noline". Except "noline", all of them accept an optional size, a color and the option "nofill".

For example, to draw the first set with blue squares (default color) of size 10 pixels, do:


xychart(a, "square:10")

To draw the second set of values with red squares of size 10 pixels and no fill, do:


xychart(b, "red", "square:10:red:nofill")

The resulting chart is shown below.


Figure 14. XY-chart with decorations.

The final example shows the use of the "rhombus", "noline" and "vertical" options. Option "vertical" draws a vertical bar connecting the data point and the x axis.


xychart(b, "red", "rhombus:15:nofill:black")
xychart(a, "vertical:#780ab0:30", "noline")

Figure 15. XY-chart with decorations.

XY-charts can also be customized using the mouse. See available keys above.

Pie charts

First create a data matrix containing names in its first column, and values in its second column.

For example (reusing data from previous section):


a=("Jessica", 45 ; "Jim", 150 ; "Janine", 15 ; "Jay", 52 ; "Jerry", 65)
"Jessica"  45
"Jim"     150
"Janine"   15
"Jay"      52
"Jerry"    65

Finally, use the pie function:


pie(a)

Figure 16 below shows the resulting chart.


Figure 16. Simple pie chart.

A title can be added using the "title:text" option as shown below.


pie(a, "title:Funny J People")

Figure 17. Simple pie chart and title.

For a complete list of optional parameters, click the icon below.

Custom colors can be specified in an optional third column.


a = ("Jessica", 45, "#5588aa" ; "Jim", 150, "#ff9999" ; "Janine", 15, "#7777ff" ; "Jay", 52, "#aa2288" ; "Jerry", 65, "gray" )
 "Jessica"  45  "#5588aa"  
 "Jim"     150  "#ff9999"  
 "Janine"   15  "#7777ff" 
 "Jay"      52  "#aa2288" 
 "Jerry"    65  "gray"
pie(a, "title:Funny J People")

Figure 18. Pie chart with custom colors.

Pie charts can be extensively customized using the mouse. The following functionality has been implemented:

The chart below is the same one as the one above but further customized using the mouse. All keys listed above (except S) were used.


Figure 19. Pie chart customized with the mouse.

By default, the program writes the names (first column of data matrix) in the legend, and the values (second column) in the pie.

To control that format, use the "format:legend_format:pie_format" option. Option "format" has this syntax:

"format:legend_format:pie_format"

where legend_format and pie_format are strings formed with numbers and/or letters and, one or more of these special combinations: #N, #V, #%.

For example,

"format:#V (#%%):#N"

The combination #N stands for the name, #V stands for the value, and #% stands for the percent. If you want the percent sign (%) to appear, you need to add it in the format string.

Using the format above, we obtain the following chart,


pie(a, "title:Funny J People", "format:#V (#%%):#N", "background:#ffeedd" )

Figure 20. Pie chart with custom formats.

Notice that option "background:color" was also used.

If you do not specify a format, the option "format:#N:#V" is used by default.

If you want to remove the legend, use the option "nolegend".