Curl Global Community
Page 6: Structure of a Program that Specifies the Graph Colors - Printable Version

+- Curl Global Community (http://communities.curl.com)
+-- Forum: Tutorials (http://communities.curl.com/forumdisplay.php?fid=3)
+--- Forum: Public Training (http://communities.curl.com/forumdisplay.php?fid=4)
+---- Forum: Curl IDE Made Easy (http://communities.curl.com/forumdisplay.php?fid=6)
+----- Forum: Try 4: Displaying Data as a Graph (http://communities.curl.com/forumdisplay.php?fid=12)
+----- Thread: Page 6: Structure of a Program that Specifies the Graph Colors (/showthread.php?tid=68)



Page 6: Structure of a Program that Specifies the Graph Colors - ashimo - 06-20-2011

Structure of the program that specifies the graph colors



Graph colors are specified with an array. First, therefore, we should explain an array.

An array consists of a group of elements that are arranged into an order. Each element has a corresponding index, beginning from 0. Array-of is one kind of array; the data type of the elements in the array is specified when the array is declared. As the data type, we can specify primitive types such as int and char, as well as class types such as String.


In Curl, we can create an array by coding the following.



Creating an Array

Code:
{{Array-of element_type} element_1, element_2, element_3, …}



For example, we would code a character string array with three elements as follows:

Code:
{{Array-of String} “ character string 1”, “character string 2”, “character string 3”}

To declare array variables, we code the following:

Code:
let array_variable_name:{Array-of element type} =
    {{Array-of data type} element_1, element_2, element_3, …}

For example, the following declaration specifies a variable called “array” which is bound to an array having three character string elements:

Code:
let array:{Array-of String} =
    {{Array-of String} “ character string 1”, “character string 2”, “character string 3”}

When we create an array in Curl, we specify the element type. There is no need to specify the size of the array in advance. The number of elements can change later.

Also, using array_name[index] syntax, we can access elements from the array. For example, to access “character string 2” whose index is 1, we specify array[1].



1. Array variable declaration

Code:
let color-array:{Array-of FillPattern} =
    {{Array-of FillPattern} orange, pink}

Graph colors are specified with a FillPattern array. FillPattern is used to specify how an object is colored. Monochrome shades can also be specified using a string.

2. Specifying the graph color

Code:
color-palette = color-array,

We can use the color-palette option of LayeredChart to specify the color of a graph. Here, we specify the array that we created in (1).