Wijmo UI for the Web
Add a TrendLine
Wijmo User Guide > Widgets > Chart Widgets > CompositeChart > CompositeChart How To > Add a TrendLine

Building on the Quick Start example, you can add a trend line to your chart using attributes of the seriesList option.

  1. In the <head> section of your HTML file, replace the script that includes the document ready function with this one, which uses data more suited to a trend line, and adds a trend line to the seriesList option using the following TrendLine attributes:
    • isTrendLine: Set this value to true to indicate that the series item is a trend line rather than a regular data item.
    • label: Set this value to "Trendline for West" for the legend so that we can distinguish it from the line chart.
    • order: Set this value to 4 to indicate the number of terms to use for the polynom equation (default fitType is polynom).
    • data: Bind the data y value to "west" to create the trend line for the column series in the chart.
    Script
    Copy Code
    <script id="scriptInit" type="text/javascript">
            var data1 = [{
                type: "Desktops",
                west: 5,
                central: 2,
                east: 3,
                Steam1: 3
            }, {
                type: "Notebooks",
                west: 3,
                central: 2,
                east: 4,
                Steam1: 6
            }, {
                type: "Tablets",
                west: 7,
                central: 2,
                east: 2,
                Steam1: 9
            }, {
                type: "Phones",
                west: 2,
                central: 1,
                east: 5,
                Steam1: 5
            }], pieData = [{
                label: "MacBook Pro",
                legendEntry: true,
                data: 46.78,
                offset: 15
            }, {
                label: "iMac",
                legendEntry: true,
                data: 23.18,
                offset: 0
            }, {
                label: "MacBook",
                legendEntry: true,
                data: 20.25,
                offset: 0
            }];
            require(["wijmo.wijcompositechart"], function () {
            $(document).ready(function () {
                $("#wijcompositechart").wijcompositechart({
                    dataSource: data1,
                    data: {x: {bind: "type"}},
                    seriesList: [{
                        type: "column",
                        label: "West",
                        data: {
                            y: {bind: "west"}
                        }
                      },{
                        type: "pie",
                        center: {x: 70, y: 70},
                        radius: 30,
                        dataSource: pieData,
                        data: {
                            label: {bind: "label"},
                            value: {bind: "data"},
                            offset: {bind: "offset"}
                        }
                      },{
                        type: "line",
                        label: "Steam1",
                        data: {
                            y: {bind: "Steam1"}
                        }
                      },{
                        isTrendline: true,
                        label: "Trendline for West",
                        order: 4,
                        data: {
                            y: {bind: "west"}
                        }
                      }
                    ]
                });
            });
            });
    </script>
  2. No changes are necessary in the <body> section of your HTML file. The basic <div> tag is sufficient to create the widget.
  3. Save your HTML file and open it in a browser. The widget appears like the one in the live widget below, with the TrendLine added to the chart.

See Also

Concepts

Widgets

Reference