Example of Creating a Line Chart

To execute the example, create an HTML page and perform the following operations:

1. Add links to JS and CSS files in the <head> tag:

2. Add style for a block with the "chart" identifier:

<style type="text/css">
    div#chart {
        border: #CCCCCC 1px solid;
        padding: 1px;
        margin: 1px;
        width: 450px;
        height: 400px;
    }
</style>

3. Add a scenario that creates a line chart:

&lt;script type=&quot;text/javascript&quot;&gt;
var chart;
// Creates a chart
function createChart() {
    // Create a line chart
    chart = new PP.Ui.Chart({
        MarkersEnabled: true, // Display data series markers
        Width: 450, // Chart width
        Height: 400, // Chart height
        ParentNode: &quot;chart&quot;,
        Type: &quot;Line&quot;, // Chart type
        // X axis
        XAxis: {
            Categories: [&quot;2001&quot;, &quot;2002&quot;, &quot;2003&quot;, &quot;2004&quot;, &quot;2005&quot;, &quot;2006&quot;, &quot;2007&quot;],
            IsX: true,
            Labels: {
                Enabled: true
            }
        },
        // Secondary Y axis
        YSAxis: {
            Enabled: false
        }
    });
}
// Returns marker for chart data series
function getMarker(borderColor) {
    var marker = {
        BorderColor: borderColor,
        BorderWidth: 2,
        Color: &quot;rgb(255, 255, 255)&quot;,
        Enabled: chart.getMarkersEnabled(),
        Radius: 8,
        Symbol: chart.getMarkersSymbol(),
    };
    return marker;
}
// Creates a color array
function getColors() {
    var colors = [
        &quot;rgb(147,61,168)&quot;,
        &quot;rgb(255,217,0)&quot;,
        &quot;rgb(255,145,145)&quot;,
        &quot;rgb(107,188,128)&quot;,
        &quot;rgb(160,203,200)&quot;,
        &quot;rgb(195,214,108)&quot;,
        &quot;rgb(239,193,100)&quot;,
        &quot;rgb(239,193,100)&quot;,
        &quot;rgb(255,191,191)&quot;,
        &quot;rgb(169,216,181)&quot;,
        &quot;rgb(205,227,226)&quot;,
        &quot;rgb(223,233,178)&quot;,
        &quot;rgb(247,223,175)&quot;,
    ];
    return colors;
}
// Creates chart data series
var serie1, serie2;
        function createSeries() {
            chart.setSeries([serie1 = createSerie1(), serie2 = createSerie2()]);
            chart.redraw(true);
        }
// Creates the first data series for line chart
function createSerie1() {
    var serie = new PP.Ui.ChartCanvasSerie({
        Click: onClick,
        Color: getColors()[0],
        CustomData: &quot;Series 1&quot;,
        Data: getSerieData1(), // Series data
        DataIndex: 0, // Data series index
        DataLabels: getDataLabels(),
        Editable: false, // Series data must not be edited
        Id: &quot;Serie0&quot;,
        IsMasterSerie: true, // Specify that data series is a forecast one
        LinePenEnabled: true, // Enable to display series lines
        MasterSerieIdx: 0, // Forecast series index
        Marker: getMarker(getColors()[0]), // Marker for chart data series
        Name: &quot;Australia&quot;, // Series name
        LineColor: getColors()[4], // Line color
        OnContextMenu: onContextMenu,
        Parent: chart,
        ParentSerieIndex: -1, // This data series is a parent one
        Threshold: '0', // Y axis starts from 0
        Type: &quot;Line&quot;,
    });
    return serie;
}
// Creates the second data series for line chart
function createSerie2() {
    var serie = new PP.Ui.ChartCanvasSerie({
        Click: onClick,
        Color: getColors()[1],
        CustomData: &quot;Series 2&quot;,
        DataIndex: 1, // Data series index
        DataLabels: getDataLabels(),
        Editable: true, // Series data can be edited
        Data: getSerieData2(), // Value array
        Id: &quot;Serie1&quot;,
        LinePenEnabled: false,
        Marker: getMarker(getColors()[1]), // Marker for chart data series
        Name: &quot;Brazil&quot;, // Series name
        LineColor: getColors()[5], // Line color
        OnContextMenu: onContextMenu,
        Parent: chart,
        ParentSerieIndex: 0, // Parent data series index
        Threshold: '0',
        Type: &quot;Line&quot;
    });
    // Set text in legend for this series
    serie.setLegendText(serie.getCustomData() + &quot;: &quot; + serie.getName());
    serie.setLegendTextWidth(5);
    return serie;
}
// Returns value array for the first data series
function getSerieData1() {
    var data = [{
        X: 0,
        Y: 10,
        Name: &quot;2001&quot;,
        Color: getColors()[0]
    }, {
        X: 1,
        Y: 30,
        Name: &quot;2002&quot;,
        Color: getColors()[1]
    }, {
        X: 2,
        Y: 17,
        Name: &quot;2003&quot;,
        Color: getColors()[2]
    }, {
        X: 3,
        Y: 25,
        Name: &quot;2004&quot;,
        Color: getColors()[3]
    }, {
        X: 4,
        Y: 55,
        Name: &quot;2005&quot;,
        Color: getColors()[4]
    }];
    return data;
}
// Returns values array for the second data series 
function getSerieData2() {
    var data = [{
        X: 0,
        Y: 15,
        Name: &quot;2001&quot;,
        Color: getColors()[5]
    }, {
        X: 1,
        Y: 24,
        Name: &quot;2002&quot;,
        Color: getColors()[6]
    }, {
        X: 2,
        Y: 19,
        Name: &quot;2003&quot;,
        Color: getColors()[7]
    }, {
        X: 3,
        Y: 29,
        Name: &quot;2004&quot;,
        Color: getColors()[8]
    }, {
        X: 4,
        Y: 28,
        Name: &quot;2005&quot;,
        Color: getColors()[9]
    }];
    return data;
}
// Processes data series point click
function onClick(sender, args) {
    if (args &amp;&amp; args.Point) {
        if (args.Point.getParent().checkPointOnPlot(args.Point)) {
            console.log(&quot;A point with the %s value is selected within chart plot area&quot;,
                args.Point.getY());
        } else {
            console.log(&quot;A point with the %s value is selected outside the chart plot area&quot;,
                args.Point.getY());
        }
    };
}
// Handles context menu call event for data series point
function onContextMenu(sender, args) {
    if (args &amp;&amp; args.Point) {
        printSerieInfo(args.Point.getParent());
    }
}
// Returns data labels for data series points
function getDataLabels() {
    var options = {
        BackgroundColor: &quot;rgb(255,239,153)&quot;,
        BorderColor: &quot;transparent&quot;,
        BorderWidth: 1,
        Font: new PP.Font(),
        Radius: 0
    };
    return options;
}
// Displays information about specified data series
function printSerieInfo(serie) {
    if (serie) {
        // Determine whether series is a forecast one
        if (serie.getIsMasterSerie()) {
            console.log(&quot;Data series ia a forecast and has the %s index&quot;,
                serie.getMasterSerieIdx());
        } else {
            console.log(&quot;Data series is not a forecast one&quot;);
        }
        console.log(&quot;Data series s% is selected&quot;, (serie.getIsSelected() ? "" : "is not "));
        console.log("The data series %s is highlighted", (serie.getHighlighted() ? "" : "not "));
        if (serie.getState === "Hover") {
            console.log("Data series is hover over with a mouse cursor");
        } else {
            console.log("Data series is not hovered over with mouse cursor");
        }
    }
}
function onReady() {
    // Create a line chart
    createChart();
    // Create chart data series
    createSeries();
    // Redraw chart
    chart.redraw(true);
}

4. Within the <body> tag specify name of the function creating a chart as the value of the onLoad attribute, and also add a block with the "chart" identifier:

<body onload="onReady()">
    <div id="chart"></div>
</body>

After executing the example the HTML page contains a line chart with two data series:

See also:

Chart