• Getting Started

  • Data

  • Chart Types

  • Chart Elements

  • Integrations

  • API

  • Tools

  • FAQ

  • Change Log

  • Labels

    Overview

    Standalone chart labels can be placed anywhere on the chart to display text, URLs, images, and more. They can utilize tokens or be paired with fixed tooltips/crosshairs to create dynamic labels. Refer to the Labels JSON Attributes/Syntax page for a full list of attribute options.

    Standalone Labels

    Get started by creating a labels array. The array will act as a container for all of your labels. Create an object for each label you want to appear on the chart.

    labels: [
      {}, // Label 1
      {}, // Label 2
      {} // Label 3
      ...
    ]
    

    At a minimum, you'll want to provide the label text with a text attribute. You can specify the positioning of the label with the x and y attributes (provide percentage or pixel values). You can also specify the label height and width with the height and width attributes (provide percentage or pixel values).

    Text

    Use the text attribute in one or multiple label objects for your chart. In the below example, multiple label objects were used to create labels with variously sized text, placement, and color.

    {
      type: 'pie',
      labels: [
        // Label 1
        {
          text: '35%',
          fontFamily: 'Georgia',
          fontSize: 50,
          x: '60%',
          y: '20%'
        },
        // Label 2
        {
          text: 'of surveyed users prefer the color',
          fontFamily: 'Georgia',
          fontSize: 12,
          x: '60%',
          y: '40%'
        },
        // Label 3
        {
          text: 'blue',
          fontColor: '#29A2CC',
          fontFamily: 'Georgia',
          fontSize: 40,
          x: '60%',
          y: '45%'
        },
        // Label 4
        {
          text: 'over other colors.',
          fontFamily: 'Georgia',
          fontSize: 12,
          x: '60%',
          y: '60%'
        }
      ],
      plot: {
        valueBox: {
          placement: 'out',
          offsetR: '-10',
          fontFamily: 'Georgia',
          fontSize: 10,
          fontWeight: 'normal'
        }
      },
      plotarea: {
        marginRight: '45%',
        marginTop: '20%',
        marginBottom: '20%'
      },
      series: [
        { values: [34]},
        { values: [30]},
        { values: [15]},
        { values: [14]},
        { values: [5]}
      ]
    }
    

    URLs

    You can incorporate links into your standalone labels with the url attribute. Provide a link to the site you want the user directed to. In the below example, users can click the blue label to learn more about the color blue.

    https://app.zingsoft.com/demos/embed/33BMQPLO
    https://app.zingsoft.com/demos/embed/33BMQPLO
    {
      type: 'pie',
      labels: [
        {
          text: 'Learn more',
          fontFamily: 'Georgia',
          fontSize: 16,
          x: '60%',
          y: '30%'
        },
        {
          text: 'about the color',
          fontFamily: 'Georgia',
          fontSize: 16,
          x: '60%',
          y: '35%'
        },
        {
          text: 'blue',
          url: 'https://en.wikipedia.org/wiki/Blue',
          target: '_blank',
          fontColor: '#29A2CC',
          fontFamily: 'Georgia',
          fontSize: 45,
          x: '60%',
          y: '40%'
        },
        {
          text: '(Click the above blue.)',
          fontFamily: 'Georgia',
          fontSize: 10,
          x: '60%',
          y: '55%'
        }
      ],
      plot: {
        valueBox: {
          placement: 'out',
          offsetR: '-10',
          fontFamily: 'Georgia',
          fontSize: 12,
          fontWeight: 'normal'
        }
      },
      plotarea: {
        marginRight: '45%',
        marginTop: '20%',
        marginBottom: '20%'
      },
      series: [
        { values: [34]},
        { values: [30]},
        { values: [15]},
        { values: [14]},
        { values: [5]}
      ]
    }
    

    Images

    To create image labels, use the background-image attribute and provide an image link. You can make sure the image fits within the label's specified height and width by adding a background-fit attribute and setting the value to xy. In the below example, an image of a blueberry was added. Users can also click on the image to be directed to a site where they can learn more about the nutritional benefits of blueberries.

    https://app.zingsoft.com/demos/embed/HNC0JZZG
    https://app.zingsoft.com/demos/embed/HNC0JZZG
    {
      type: 'pie',
      labels: [
        {
          text: "What's blue?",
          fontFamily: 'Georgia',
          fontSize: 16,
          x: '60%',
          y: '20%'
        },
        {
          text: 'Blueberries',
          fontColor: '#29A2CC',
          fontFamily: 'Georgia',
          fontSize: 36,
          x: '60%',
          y: '26%'
        },
        {
          backgroundImage: 'https://www.zingchart.com/images/blueberry.jpg',
          backgroundFit: 'xy',
          url: 'http://www.whfoods.com/genpage.php?tname=foodspice&dbid=8',
          target: '_blank',
          x: '60%',
          y: '40%',
          height: '30%',
          width: '30%'
        },
        {
          text: '(Click the blueberries.)',
          fontFamily: 'Georgia',
          fontSize: 10,
          x: '60%',
          y: '71%',
        }
      ],
      plot: {
        valueBox: {
          placement: 'out',
          offsetR: '-10',
          fontFamily: 'Georgia',
          fontSize: 12,
          fontWeight: 'normal'
        }
      },
      plotarea: {
        marginRight: '45%',
        marginTop: '20%',
        marginBottom: '20%'
      },
      series: [
        { values: [34]},
        { values: [30]},
        { values: [15]},
        { values: [14]},
        { values: [5]}
      ]
    }
    

    Styling

    When styling your labels, you can customize the fonts, backgrounds, borders, and more. Here is a line chart with custom styling, including gradient backgrounds and rounded borders. Refer to the Labels JSON Attributes/Syntax page for a full list of available attributes.

    Note: The chart also utilizes the %plot-#-value token so that when users hover over a node index, the corresponding values appear in the labels. Tokens are further discussed in the Dynamic Labels section below.

    https://app.zingsoft.com/demos/embed/IUP6JZQ2
    https://app.zingsoft.com/demos/embed/IUP6JZQ2
    {
      type: 'line',
      labels: [
        {
          text: 'Blue:<br>%plot-0-value',
          defaultValue: '__',
          x: '15%',
          y: '7%',
          backgroundColor: 'blue #29A2CC',
          fontFamily: 'Georgia',
          fontColor: 'white',
          fontSize: 14,
          height: '15%',
          width: '10%',
          borderRadius: '5px'
        },
        {
          text: 'Red:<br>%plot-1-value',
          defaultValue: '__',
          x: '30%',
          y: '7%',
          backgroundColor: 'red #D31E1E',
          fontFamily: 'Georgia',
          fontColor: 'white',
          fontSize: 14,
          height: '15%',
          width: '10%',
          borderRadius: '5px'
        },
        {
          text: 'Green:<br>%plot-2-value',
          defaultValue: '__',
          x: '45%',
          y: '7%',
          backgroundColor: 'green #7CA82B',
          fontFamily: 'Georgia',
          fontColor: 'white',
          fontSize: 14,
          height: '15%',
          width: '10%',
          borderRadius: '5px'
        },
        {
          text: 'Orange:<br>%plot-3-value',
          defaultValue: '__',
          x: '60%',
          y: '7%',
          backgroundColor: 'orange #EF8535',
          fontFamily: 'Georgia',
          fontColor: 'white',
          fontSize: 14,
          height: '15%',
          width: '10%',
          borderRadius: '5px'
        },
        {
          text: 'Purple:<br>%plot-4-value',
          defaultValue: '__',
          x: '75%',
          y: '7%',
          backgroundColor: 'purple #A14BC9',
          fontFamily: 'Georgia',
          fontColor: 'white',
          fontSize: 14,
          height: '15%',
          width: '10%',
          borderRadius: '5px'
        }
      ],
      crosshairX: {
        plotLabel: {
          visible: false
        },
        scaleLabel: {
          visible: false
        }
      },
      plot: {
        tooltip: {
          visible: false
        }
      },
      plotarea: {
        marginTop: '25%'
      },
      series: [
        { values: [3,4,11,5,19,7]},
        { values: [9,19,15,25,12,14]},
        { values: [15,29,19,21,25,36]},
        { values: [19,15,21,29,31,20]},
        { values: [33,23,39,34,5,31]}
      ]
    }
    

    Dynamic Labels

    Dynamic labels respond to the user's movement over the node values (or data points) on the chart. There are several label-specific tokens that allow you to create these interactive labels. You can also combine standalone labels with fixed tooltips or crosshairs to create dynamic labels.

    Placement

    As you have seen, you can place labels based on x/y positions. But what about something a bit more dynamic? You have the ability to hook labels to nodes and scales. Check out the labels doc for more information.

    Static labels hooked to nodes.

    https://app.zingsoft.com/demos/embed/WOYP144O
    https://app.zingsoft.com/demos/embed/WOYP144O

    Dynamic labels hooked to nodes.

    https://app.zingsoft.com/demos/embed/ILL6MZ6V
    https://app.zingsoft.com/demos/embed/ILL6MZ6V

    Static labels hooked to scales.

    https://app.zingsoft.com/demos/embed/CQEBIDX2
    https://app.zingsoft.com/demos/embed/CQEBIDX2

    Tokens

    The following tokens can be used with standalone labels. Because they are not tied to the nodes, standalone labels differ from other label types such as value boxes, tooltips, and crosshairs in that they cannot utilize many of the node-tied tokens.

    Token Description
    (%node-value)(#)(#) Node value of a specified plot and node index, provided in the following format: (%node-value)(plot number)(node index number), e.g., (%node-value)(0)(0)). Note: Plot and node index numbering begins at zero.
    %node-percent-value %npv Percentage value of the hovered over node relative to the sum of all nodes. Demo
    %plot-#-value Node value of a specified plot, provided in the following format: %plot-plot number-value, e.g., %plot-0-value. This token is best used with crosshairs. Note: Plot numbering begins at zero. Demo
    %plot-value Node value of the hovered over value. This token is best used with tooltips. Demo

    Here is a pie chart using the %plot-value token. When users hover over a pie slice, the corresponding value appears in the label.

    https://app.zingsoft.com/demos/embed/Q60WRTQO
    https://app.zingsoft.com/demos/embed/Q60WRTQO
    {
      type: 'pie',
      labels: [
        {
          text: 'The value of<br>the hovered over<br>pie slice<br>is',
          textAlign: 'left',
          fontFamily: 'Georgia',
          fontSize: 16,
          x: '60%',
          y: '30%'
        },
        {
          text: '%plot-value',
          defaultValue: '__',
          fontFamily: 'Georgia',
          fontSize: 34,
          x: '65%',
          y: '44%'
        },
        {
          text: '.',
          fontFamily: 'Georgia',
          fontSize: 16,
          x: '73%',
          y: '50%'
        }
      ],
      plot: {
        valueBox: {
          placement: 'out',
          offsetR: '-10',
          fontFamily: 'Georgia',
          fontSize: 12,
          fontWeight: 'normal'
        }
      },
      plotarea: {
        marginRight: '45%',
        marginTop: '20%',
        marginBottom: '20%'
      },
      series: [
        { values: [34]},
        { values: [30]},
        { values: [15]},
        { values: [14]},
        { values: [5]}
      ]
    };
    

    Fixed Tooltips

    You can place fixed tooltips on top of standalone labels to create dynamic labels that utilize the full range of available node tokens. Refer to our documentation on ZingChart tokens to browse a full tokens list. Use the x and y attributes to specify where the tooltips appear on the chart. You can use the sticky (set to true) and timeout (provide a value in milliseconds) attributes to specify how long the tooltips stay on the screen. Refer to the Tooltips Tutorial for more information. Here is a calendar chart that displays dynamic labels via fixed tooltips and standalone labels.

    https://app.zingsoft.com/demos/embed/8QV0HJY4
    https://app.zingsoft.com/demos/embed/8QV0HJY4
    {
      type: 'calendar',
      title: {
        text: 'Donations',
        fontFamily: 'Georgia',
      },
      options: {
        year: {
          text: '2016',
          visible: false,
        },
        startMonth: 1, //January
        endMonth: 6, //March
        firstday: 's', //Sunday,
        palette: [ 'black', '#3399ff', '#e6f2ff' ], //Negative, positive, and optional zero value
        weekday: {
          values: [ '', 'M', '', 'W', '', 'F', '' ],
          item: {
            fontColor: 'gray',
            fontSize: 9
          }
        },
        month: {
          item: {
            fontColor: 'gray',
            fontSize: 9
          }
        },
        values: [
          //Omitted for brevity.
        ]
      },
      tooltip: {   //Fixed Tooltip
        text: '%data-day',
        fontFamily: 'Georgia',
        fontColor: '#001a33',
        backgroundColor: 'none',
        borderColor: 'none',
        sticky: true,
        timeout: 30000,
        x: '20%',
        y: '78%'
      },
      labels: [
        {
          borderWidth: '1px',
          borderColor: 'gray',
          width: '40%',
          height: '30%',
          x: '8%',
          y: '60%',
        },
        {
          text: 'Daily Donation Count',
          fontFamily: 'Georgia',
          fontColor: '#001a33',
          x: '18%',
          y: '65%'
        },
        { //Dynamic Label with Token
          text: '%plot-value',
          fontColor: '#3399ff',
          fontSize: 35,
          fontFamily: 'Georgia',
          x: '23%',
          y: '68%'
        },
        {
          borderWidth: '1px',
          borderColor: 'gray',
          width: '40%',
          height: '30%',
          x: '52%',
          y: '60%'
        },
        {
          text: 'Total Donations',
          fontFamily: 'Georgia',
          fontColor: '#001a33',
          x: '65%',
          y: '65%'
        },
        {
          text: '6808',
          fontColor: '#3399ff',
          fontSize: 35,
          fontFamily: 'Georgia',
          x: '65%',
          y: '68%'
        },
        {
          text: 'Jan 1 - Jun 30',
          fontFamily: 'Georgia',
          fontColor: '#001a33',
          x: '65%',
          y: '80%'
        }
      ],
      plotarea: {
        marginTop: '20%',
        marginBottom: '50%',
        marginLeft: '8%',
        marginRight: '8%'
      }
    }
    

    Fixed Crosshairs

    You can layer fixed crosshairs on top of standalone labels to create dynamic labels that utilize the full range of available node tokens. Refer to our documentation on ZingChart tokens to browse a full tokens list. Use the x and y attributes to specify where the crosshair labels appear. You can use the sticky (set to true) and timeout (provide a value in milliseconds) attributes to specify how long the labels stay on the screen. Refer to the Crosshairs Tutorial for more information. Here is a stock and volume chart created via a mixed chart and blended scales.

    Note: On crosshairs, the x and y attributes are relative to the plotarea, and not the entire chart area. The provided percentage values may thus be below or over 0 or 100%.

    https://app.zingsoft.com/demos/embed/34545TBY
    https://app.zingsoft.com/demos/embed/34545TBY
    {
      type: 'mixed',
      title: {
        text: 'Stock & Volume',
        fontFamily: 'Georgia'
      },
      labels: [
        {
          text: 'Price',
          fontFamily: 'Georgia',
          fontSize: 10,
          verticalAlign: 'top',
          backgroundColor: 'white',
          borderWidth: '1px',
          borderColor: 'gray',
          borderRadius: '5px',
          x: '75%',
          y: '15%',
          height: '45%',
          width: '20%',
          padding: '15%'
        },
        {
          text: 'Shares Sold',
          fontFamily: 'Georgia',
          fontSize: 10,
          verticalAlign: 'top',
          backgroundColor: 'white',
          borderWidth: '1px',
          borderColor: 'gray',
          borderRadius: '5px',
          x: '75%',
          y: '65%',
          height: '23%',
          width: '20%',
          padding: '13%'
        }
      ],
      plot: {
        tooltip: {
          visible: false
        }
      },
      plotarea: {
        marginRight: '30%'
      },
      scaleX: {
        minValue: 1420232400000,
        step: 'day',
        transform: {
          type: 'date',
          all: '%m/%d'
        },
        maxItems: 4,
        item: {
          fontSize: 10
        },
        zooming: true,
        zoomToValues: [1420232400000,1425070800000]
      },
      scrollX: {},
      scaleY: {
        offsetStart: '35%',
        values: '29:33:2',
        format: '$%v',
        label: {
          text: 'Prices'
        },
        guide: {
          lineStyle: 'solid'
        },
        item: {
          fontSize: 10
        }
      },
      scaleY2: {
        blended: true,
        offsetEnd: '75%',
        placement: 'default',
        values: '0:3:3',
        format: '%vM',
        label: {
          text: 'Volume'
        },
        guide: {
          lineStyle: 'solid'
        },
        item: {
          fontSize: 10
        }
      },
      crosshairX: {
        plotLabel: {
          multiple: true
        },
        scaleLabel: {
          text: '%v',
          transform: {
            type: 'date',
            all: '%D, %m/%d/%y'
          }
        }
      },
      series: [
        {
          type: 'stock',
          scales: 'scale-x,scale-y',
          aspect: 'candlestick',
          guideLabel: {
            text: 'Open: $%open<br>High: $%high<br>Low: $%low<br>Close: $%close',
            transform: {
              type: 'date',
              all: '%D, %m/%d/%y'
            },
            fontColor: '#0099cc',
            fontFamily: 'Georgia',
            fontSize: 16,
            textAlign: 'center',
            backgroundColor: 'none',
            borderColor: 'none',
            height: '40%',
            width: '25%',
            x: '125%', //relative to the plotarea
            y: '36%', //relative to the plotarea
            sticky: true,
            timeout: 20000,
            callout: false
          },
          trendUp: {
            backgroundColor: '#ccccff',
            lineColor: 'gray',
            borderColor: 'gray'
          },
          trendDown: {
            backgroundColor: '#ffe6ff',
            lineColor: 'gray',
            borderColor: 'gray'
          },
          values: [...]
        },
        {
          type: 'bar',
          scales: 'scale-x,scale-y-2',
          guideLabel: {
            text: '%vM',
            fontColor: '#0099cc',
            fontFamily: 'Georgia',
            fontSize: 26,
            textAlign: 'center',
            backgroundColor: 'none',
            borderColor: 'none',
            height: '10%',
            width: '25%',
            x: '125%', //relative to the plotarea
            y: '110%', //relative to the plotarea
            sticky: true,
            timeout: 20000,
            callout: false
          },
          backgroundColor: '#ccf2ff',
          borderWidth: '1px',
          borderColor: 'gray',
          values: [...]
        }
      ]
    }
    

    Summary

    Labels allow you to add any text or image, anywhere on your chart. They're great for calling attention to additional data or annotating your chart. For a full list of label attributes, see the JSON configuration page.