Wijmo UI for the Web
Add Annotations
Wijmo User Guide > Widgets > Chart Widgets > BarChart > BarChart How To > Add Annotations

Annotations are used to mark important news or events that can be attached to a specific data point on a chart. Users can hover over the data point to display the full annotation text. Wijbarchart annotation lets a user add different types of annotations on the chart, including text, shapes, images. There are various built-in shapes which are supported as annotations in wijmo charts, such as circle, ellipse, image, line, polygon, rectangle, square and text.

You can specify the position of annotation on charts by using the point property and setting its x and y co-ordinates.

To specify the attachment of annotation in a barchart, you can use the attachment property of annotations, and set its value to:

You can add annotations to various chart types, including BubbleChart, CompositeChart, CandleStickChart, LineChart and ScatterChart.

Script
Copy Code
<script id="scriptInit" type="text/javascript">
    require(["wijmo.wijbarchart"], function () {
        $(document).ready(function () {
            var North = {
                label: "North",
                legendEntry: true,
                data: { x: [new Date(2015, 4, 17), new Date(2015, 4, 18), new Date(2015, 4, 19), new Date(2015, 4, 20), new Date(2015, 4, 21)], y: [20, 22, 19, 24, 25] }
            }, East = {
                label: "East",
                legendEntry: true,
                data: { x: [new Date(2015, 4, 17), new Date(2015, 4, 18), new Date(2015, 4, 19), new Date(2015, 4, 20), new Date(2015, 4, 21)], y: [8, 12, 10, 12, 15] }
            }, South = {
                label: "South",
                legendEntry: true,
                data: { x: [new Date(2015, 4, 17), new Date(2015, 4, 18), new Date(2015, 4, 19), new Date(2015, 4, 20)], y: [12, 8, 20, 10] }
            }, West = {
                label: "West",
                legendEntry: true,
                data: { x: [new Date(2015, 4, 17), new Date(2015, 4, 18), new Date(2015, 4, 19), new Date(2015, 4, 20), new Date(2015, 4, 21)], y: [8, 10, 15, 17, 21] }
            };


            $("#wijbarchart").wijbarchart({
                horizontal: false,
                seriesList: [North, East, South, West],
                showChartLabels: false,
                axis: {
                    x: {
                        text: "Date",
                        annoFormatString: "D"
                    },
                    y: {
                        text: "Sales Amount"
                    }
                },
                legend: {
                    compass: "east",
                    orientation: "vertical",
                    text: "Legend"
                },
                header: {
                    text: "Sales of 2014"
                },
                annotations: [
                    {
                        type: "circle",
                        content: "Relative [Center]",
                        tooltip: "Relative [Center]",
                        attachment: "relative",
                        radius: 50,
                        point: { x: 0.5, y: 0.5 },
                        style: { fill: '#01DFD7' }
                    },                
                    {
                        type: "circle",
                        content: "Absolute",
                        tooltip: "Absolute",
                        attachment: "absolute",
                        radius: 45,
                        point: { x: 120, y: 230 },
                        style: { fill: '#AA99D0' }
                    },
                    {
                        type: "image",
                        attachment: "dataIndex",
                        href: "http://wijmo.com/wp-content/themes/wijmo5/img/wijmo_flexible.png",
                        tooltip: "wijmo_flexible.png",
                        content: "Image",
                        width: 60,
                        height: 60,
                        position:"top",
                        seriesIndex: 1,
                        pointIndex: 3
                    },
                    {
                        type: "circle",
                        content: "DATA",
                        tooltip: "DATA",
                        attachment: "dataIndex",
                        seriesIndex: 0,
                        pointIndex: 4,
                        radius: 20,
                        position:"left top",
                        style: { fill: '#FF1109', "fill-opacity": 0.22 }
                    },                    
                    {
                        type: "rect",
                        content: "SerieThree",
                        tooltip: "SerieThree",
                        attachment: "dataIndex",
                        seriesIndex: 2,
                        pointIndex: 0,
                        width: 50,
                        height: 30,
                        r: 3,
                        style: {
                            "fill": "#FE2E2E",
                            "stroke": "#FFA9DB",
                            "fill-opacity": 0.5,
                            "stroke-width": 2,
                            "stroke-opacity": 0.75
                        }
                    },
                    {
                        type: "ellipse",
                        content: "SerieTwoPointFour",
                        tooltip: "SerieTwoPointFour",
                        attachment: "dataIndex",
                        seriesIndex: 1,
                        pointIndex: 4,
                        width: 90,
                        height: 30,
                        r: 3,
                        style: {
                            "fill": "#FF7700",
                            "stroke": "#FFA9DB",
                            "fill-opacity": 0.5,
                            "stroke-width": 2,
                            "stroke-opacity": 0.75
                        }
                    },
                    {
                        type: "line",
                        content: "LineText",
                        tooltip: "LineText",
                        start: { x: 10, y: 10 },
                        end: { x: 100, y: 100 },
                        style: {
                            "fill": "#FE2E2E",
                            "stroke": "#01A9DB",
                            "fill-opacity": 2,
                            "stroke-width": 5,
                            "stroke-opacity": 1
                        }
                    },
                    {
                        type: "text",
                        text: "TextOnlyAnnotation",
                        tooltip: "TextOnlyAnnotation",
                        point: { x: 350, y: 25 },
                        style: {
                            "fill": "#FE2E2E",
                            "stroke": "#01A9DB",
                            "font-size": 18
                        }
                    }                        
                ]
            });
        });
    });
</script>