SPL Programming - 12.4 [Drawing graphics] Legend

 

We never explained how the colors of these columns and dots came from. Moreover, there are legends in the finished graph, but it has not appeared when we draw a graph by ourselves. How should it be drawn?

The introduction of logical axis can realize the mapping from business data to physical position. We can draw a dot at the position of (East,40), and the logical axis will be responsible for finding the correct physical position.

Similarly, the legend is also a mapping, which is responsible for mapping the business data into colors. Since we can draw a dot at (East,40), we should also be able to use the East color to draw a column. Whether to use red or blue when drawing on the graph is determined by the legend. Later, to change the mapping mode in the legend, we can get different graphics without changing the plot() statement itself.

In this sense, the legend can also be regarded as some kind of axis, but it maps the business data to the color of the element, not the position. In fact, not only colors can be mapped, but colors are the most commonly used. If we want to obtain black-and-white graphics (such as for printing), it is easy to be confused to distinguish by color. At this time, we can use shape, linetype and other appearance properties to distinguish. The task of the legend is to map the business data to some appearance property of the element.

Let’s try to control the color of the column by ourselves. First edit a legend, select the legend in the element list, give the legend a name (called manager here, which will be used later), and then find the arrow on the right of the following two properties in the property list and click:

imagepng

imagepng

A list will appear in the right half of the editing dialog, in which you can fill in the following lines (click the color column to pop up another dialog box to select the color):

imagepng

You can see that the property list on the left has been filled in. Actually, it is OK to fill in directly on the left, but because the sequence members as properties should correspond one by one, it is easy to misplace if filling in directly, so use the list on the right to assist.

Because color is very complex information, the edited plot() statement is very complex and long.

Now let’s use this legend:

A B C
1 [10,20,40,30,50] [East,North,West,South,Center] [John,Alice,John,Mary,Alice]
2 =canvas()
3 =A2.plot(“Legend”,“name”:“manager”,“legendText”:[“John”,“Alice”,“Mary”],“legendFillColor”:[[“ChartColor”,0,false,-65536,-5252872,0],[“ChartColor”,0,false,-16776961,-5252872,0],[“ChartColor”,0,false,-16711936,-5252872,0]])
4 =A2.plot(“EnumAxis”,“name”:“area”)
5 =A2.plot(“NumericAxis”,“name”:“amount”,“location”:2)
6 =A2.plot(“Column”,“fillColor”:C1:“manager”,“axis1”:“area”,“data1”:B1,“axis2”:“amount”,“data2”:A1)
7 =A2.draw(600,400)

A2 is the legend statement just edited.

A sequence is added to the data to represent the manager in charge of each region. There may be multiple regions that are in charge by the same manager. Seeing the names, we know that we are going to use different colors to represent different managers.

When editing the A6 plot column statement, fill in the appearance property like this, use the value in sequence C1 as the color, and the legend name is manager.

imagepng

SPL will successively use the members of C1 to get the actual colors from the legend manager to draw the picture.

imagepng

At the same time, the legend is also drawn to the edge. Modifying the properties of the legend element can change its position.

Let’s go back to the question mentioned earlier. Why do a row of dots and columns automatically have different colors?

If no definite color is selected during drawing, SPL will automatically set a default legend for the element. If there is an enumeration axis in the drawing, the color will correspond to the coordinates of this enumeration axis. The default legend is called Legend. We can draw it:

A B
1 [10,20,40,30,50] [East,North,West,South,Center]
2 =canvas() =A2.plot(“Legend”)
3 =A2.plot(“EnumAxis”,“name”:“area”)
4 =A2.plot(“NumericAxis”,“name”:“amount”,“location”:2)
5 =A2.plot(“Column”,“axis1”:“area”,“data1”:B1,“axis2”:“amount”,“data2”:A1)
6 =A2.draw(600,400)

imagepng

Let’s try other appearance properties and draw this graph with dots of different shapes.

A B C
1 [10,20,40,30,50] [East,North,West,South,Center] [John,Alice,John,Mary,Alice]
2 =canvas()
3 =A2.plot(“Legend”,“name”:“manager”,“legendText”:[“John”,“Alice”,“Mary”],“legendType”:2,“legendFillColor”:[“ChartColor”,0,false,-16777216,-5252872,0],“legendMarkerShape”:[1,2,3])
4 =A2.plot(“EnumAxis”,“name”:“area”)
5 =A2.plot(“NumericAxis”,“name”:“amount”,“location”:2)
6 =A2.plot(“Dot”,“markerStyle”:C1:“manager”,“lineColor”:-16777216,“markerColor”:[“ChartColor”,0,false,-16777216,-5252872,0],“radius1”:0.2,“radius2”:1,“axis1”:“area”,“data1”:B1,“axis2”:“amount”,“data2”:A1)
7 =A2.draw(600,400)

When defining the legend in A3, use the dot type, select different shapes as the rendering properties of the legend, and select the fill color as black, otherwise SPL will draw the legend in color by default.

imagepng

Use the dot element in A6 to correspond the shape to the legend, and increase the radius of the dot to see it more clearly (the unit of radius is determined by the logical axis of the horizontal axis and the vertical axis, and the distance between two adjacent members of the enumeration axis is 1), and the line color and fill color are set to black.

imagepng

Draw a black-and-white graph without color:

imagepng