This section describes the various types of line charts that you can create using the Image Chart API.
There are a variety of line charts that you can create. Specify a line chart with the following syntax:
lcA line chart where data points are spaced evenly along the x-axis. Axis lines are shown by default. To show values on the axis lines, you must specify chxt.
lccharts, but by default does not display axis lines. These are also known as sparklines.
lxyLets you specify both x- and y-coordinates for each point, rather just the y values.
To specify data points for
lxy charts, you must specify series in multiples of two. The first series in each pair is the x coordinates for that line, and the second series is the corresponding y coordinates for that line. For example:
cht=lxy chd=t:<line_1_x1>,<line_1_x2>,...|<line_1_y1>,<line_1_y2>,...| <line_2_x1>,<line_2_x2>,...|<line_2_y1>,<line_2_y2>,...
To space the data points evenly along the x-axis only, provide a single undefined value for the x set for that series. In this example, the red "Unicorns" line spaces the data points evenly along the x-axis. For more information about undefined values, see Data formats.
In this example, the "Ponies" line specifies exact x- and y-values for all points, and the "Unicorns" line spaces the values evenly along the x-axis.
cht=lxy chd=t: 10,20,40,80,90,95,99| 20,30,40,50,60,70,80| -1| 5,10,22,35,85
Take care not to overestimate the number of data points required for your line chart. For example, to show how popular chocolate ice cream was over the last ten years, aggregating search queries for each day would result in more than 3,600 values. It would not make any sense to plot a graph at this granularity. On a chart 1024 pixels wide, one data point would be about a quarter of a pixel. (Additionally, this would be too much data to pass in a URL). The following examples illustrate this point.
600 pixel wide chart with 40 data points (15 pixels per data point):
300 data points (2 pixel per data point):
600 data points (1 pixel per data point):
900 data points (less than 1 pixel per data point):
You can specify the colors of a specific series, or all series, using the chco parameter.
chco=<color_1>, ... <color_n>
<color>An RRGGBB[AA] hexadecimal format format hexadecimal number. Specify a single value to apply the same color to all series. Specify different colors for different series by adding color values separated by a comma. If you have fewer colors than you have series, the unspecified series will cycle through the specified colors from the beginning.
When you specify a single color for each series, each series gets the color assigned. This example has three data series and three colors specified.
The following example also has three data series, but only two colors are specified. Because the color for the third series is unspecified, the third line is drawn using the first color (orange).
You can specify line thickness and solid/dashed style with the
chls parameter. This parameter can only be used to style lines in line or radar charts; you cannot use it to style the line in a compound chart lines, unless the base type of the compound chart is a line chart.
Separate multiple line styles by the pipe character (
|); the first style applies to the first line, the second to the next, and so on. If you have fewer styles than lines, the default style is applied to all the unspecified lines.
chls= <line_1_thickness>,<opt_dash_length>,<opt_space_length> |...| <line_n_thickness>,<opt_dash_length>,<opt_space_length>
<line_1_thickness>Thickness of the line, in pixels.
<opt_dash_length>, <opt_space_length>[Optional] Used to define dashed grid lines. The first parameter is the length of each line dash, in pixels. The second parameter is the spacing between dashes, in pixels. For a solid line, specify neither value. If you only specify
<opt_space_length>will be set to
<opt_dash_length>. Default is
1,0(a solid line).
Here the dashed line is specified by
3,6,3 and the thicker, solid line is specified by
Now let's use various line thickness:
You can fill the area below a data line with a solid color.
You can combine line fills with any other
chm parameters using a pipe character (
| ) to separate the chm parameters.
chm= <b_or_B>,<color>,<start_line_index>,<end_line_index>,<0> |...| <b_or_B>,<color>,<start_line_index>,<end_line_index>,<0>
<b_or_B>Whether to fill to the bottom of the chart, or just to the next lower line.
- B - Fill from
<start_line_index>to the bottom of the chart.
<end_line_index>supports a special syntax to let you fill a segment of the chart. This is easiest if you have a chart with a single line that you want to fill.
- b - Fill between two lines in a multi-line chart. Start and end lines are indicated by
- B - Fill from
<color>An RRGGBB format hexadecimal number of the fill color
<start_line_index>The index of the line at which the fill starts. The first data series specified in chd has an index of zero (0), the second data series has an index of 1, and so on.
- Fill type 'b' - The line at which to stop the fill. This line must be below the current line.
- Fill type 'B' - One of the following choices:
- any value - Any single number in this parameter is ignored, and the fill will go from the specified line to the base of the chart
start:end - To fill a vertical slice below the chart, specify start:end, where these are data point indices describing where to start and stop the fill. Both values are optional, and default to first_point:last_point. (See example below.)
- <0> Reserved — must be zero.
The following example fills the entire area under the line.
The following example has 3 series, 3 lines and 2 fills. First serie (
0,1) has an orange color fill (
#fdb45c), second serie (
1,2) has a red color fill (
The following example fills 2 datasets with yellow (consumed) and grey (prevision) colors.