Line Chart

Data that's arranged in columns or rows on a worksheet can be plotted in a line chart. In a line chart, category data is distributed evenly along the horizontal axis, and all value data is distributed evenly along the vertical axis. Line charts can show continuous data over time on an evenly scaled axis, making them ideal for showing trends in data at equal intervals, like months, quarters, or fiscal years.

Description
app.vue
index.html
Copy to CodeMine

SpreadJS supports line, stacked line, 100% stacked line, line with markers, stacked line with markers, and 100% stacked line with markers charts. Use the GC.Spread.Sheets.Charts.ChartType.line property to get the chart type.

You can add a line chart to Spread and change its style(like smooth) using the chart API:

     var chart = sheet.charts.add('line', GC.Spread.Sheets.Charts.ChartType.line, 0, 100, 400, 300, 'A1:D4');
     var series0 = chart.series().get(0);
     series0.smooth = true;
     chart.series().set(0, series0);
     var legend = chart.legend();
     legend.visible = true;
     chart.legend(legend);

The line chart can be stacked normally or to add up to 100 percent, with or without markers.

You can customize the color, shape, border of marker at the series with markers..

    var seriesItem = chart.series().get(index ?);
    bobSeries.symbol.shape = 1 /** dash */;
    bobSeries.symbol.size = 20;
    bobSeries.symbol.fill = "red";
    bobSeries.symbol.border.size = 2;
    bobSeries.symbol.border.color = "rgb(127, 0, 127)";
    bobSeries.symbol.border.lineType = 7 /** sysDot */;
    series.set(index ?, seriesItem);

Line and Line with markers: Line charts can be shown with or without markers to indicate individual data values. Line charts are useful for showing trends over time or over evenly-spaced categories, especially when you have many data points and the order in which they are presented is important. If there are many categories or the values are approximate, it’s best to use a line chart without markers.

Stacked line and Stacked line with markers: Stacked line charts can show the trend of the contribution of each value over time or over evenly-spaced categories.

100% stacked line and 100% stacked line with markers: One-hundred percent stacked line charts can show the trend of the percentage each value contributes over time or evenly-spaced categories. If there are many categories or the values are approximate, use a 100% stacked line chart without markers.

SpreadJS supports line, stacked line, 100% stacked line, line with markers, stacked line with markers, and 100% stacked line with markers charts. Use the GC.Spread.Sheets.Charts.ChartType.line property to get the chart type. You can add a line chart to Spread and change its style(like smooth) using the chart API: The line chart can be stacked normally or to add up to 100 percent, with or without markers. You can customize the color, shape, border of marker at the series with markers.. Line and Line with markers: Line charts can be shown with or without markers to indicate individual data values. Line charts are useful for showing trends over time or over evenly-spaced categories, especially when you have many data points and the order in which they are presented is important. If there are many categories or the values are approximate, it’s best to use a line chart without markers. Stacked line and Stacked line with markers: Stacked line charts can show the trend of the contribution of each value over time or over evenly-spaced categories. 100% stacked line and 100% stacked line with markers: One-hundred percent stacked line charts can show the trend of the percentage each value contributes over time or evenly-spaced categories. If there are many categories or the values are approximate, use a 100% stacked line chart without markers.
<template> <div class="sample-tutorial"> <gc-spread-sheets class="sample-spreadsheets" @workbookInitialized="initSpread"> <gc-worksheet /> <gc-worksheet /> <gc-worksheet /> <gc-worksheet /> <gc-worksheet /> <gc-worksheet /> </gc-spread-sheets> </div> </template> <script setup> import GC from "@mescius/spread-sheets"; import { ref } from "vue"; import "@mescius/spread-sheets-vue"; import "@mescius/spread-sheets-charts"; const spreadRef = ref(null); function initSpread(spread) { spreadRef.value = spread; let chartType = [{ type: GC.Spread.Sheets.Charts.ChartType.line, desc: "line", }, { type: GC.Spread.Sheets.Charts.ChartType.lineStacked, desc: "lineStacked", }, { type: GC.Spread.Sheets.Charts.ChartType.lineStacked100, desc: "lineStacked100", }, { type: GC.Spread.Sheets.Charts.ChartType.lineMarkers, desc: "lineMarkers", withMarker: true, }, { type: GC.Spread.Sheets.Charts.ChartType.lineMarkersStacked, desc: "lineMarkersStacked", withMarker: true, }, { type: GC.Spread.Sheets.Charts.ChartType.lineMarkersStacked100, desc: "lineMarkersStacked100", withMarker: true, }]; spread.suspendPaint(); let sheets = spread.sheets; for (let i = 0; i < chartType.length; i++) { let sheet = sheets[i]; initSheet(sheet, chartType[i].desc); initChart(sheet, chartType[i].type, chartType[i].withMarker); //add chart } spread.options.tabStripRatio = 0.8; spread.resumePaint(); } function initSheet(sheet, sheetName) { sheet.name(sheetName); //prepare data for chart let dataArray = [ ["", '2012', '2013', '2014', '2015', '2016', '2017'], ["Chrome", 0.3782, 0.5663, 0.4966, 0.6689, 0.4230, 0.6360], ["FireFox", 0.1284, 0.2030, 0.2801, 0.2560, 0.1531, 0.3304], ["IE", 0.3214, 0.2491, 0.2455, 0.1652, 0.2073, 0.0834], ]; sheet.setArray(0, 0, dataArray); } function initChart(sheet, chartType, marker) { //add chart let chart = sheet.charts.add((sheet.name() + 'Chart1'), chartType, 10, 85, 450, 350, "A1:G4", GC.Spread.Sheets.Charts.RowCol.rows); changeChartLegend(chart); changeChartArea(chart); changChartDataLabels(chart); changeGridLines(chart); changeLineStyle(chart, false); changeChartAxes(chart); changeChartTitle(chart); if (marker) { changeMarker(chart); } chart = sheet.charts.add((sheet.name() + 'Chart2'), chartType, 470, 85, 450, 350, "A1:G4", GC.Spread.Sheets.Charts.RowCol.rows); changeChartLegend(chart); changeChartArea(chart); changChartDataLabels(chart); changeGridLines(chart); changeLineStyle(chart, true); changeChartAxes(chart); changeChartTitle(chart); if (marker) { changeMarker(chart); } } function changeChartTitle(chart) { let title = chart.title(); title.text = "Browser Market Share"; title.fontSize = 18; chart.title(title); } //change legend position function changeChartLegend(chart) { let legend = chart.legend(); legend.visible = true; let legendPosition = GC.Spread.Sheets.Charts.LegendPosition; legend.position = legendPosition.bottom; chart.legend(legend); } //change backColor function changeChartArea(chart) { let chartArea = chart.chartArea(); chartArea.fontSize = 14; chart.chartArea(chartArea); } // show dataLabels function changChartDataLabels(chart) { let dataLabels = chart.dataLabels(); dataLabels.showValue = true; dataLabels.showSeriesName = false; dataLabels.showCategoryName = false; dataLabels.format = "0%"; let dataLabelPosition = GC.Spread.Sheets.Charts.DataLabelPosition; dataLabels.position = dataLabelPosition.above; chart.dataLabels(dataLabels); } // hide gridLines function changeGridLines(chart) { let gridLinesAxes = chart.axes(); gridLinesAxes.primaryValue.min = null; chart.axes(gridLinesAxes); } //change legend position function changeChartAxes(chart) { chart.axes({ primaryValue: { format: "0%" } }); } // change line style function changeLineStyle(chart, smooth) { let series = chart.series().get(); let seriesItem; for (let i = 0; i < series.length; i++) { seriesItem = series[i]; seriesItem.border.width = 2; seriesItem.smooth = smooth; chart.series().set(i, seriesItem); } } // change Marker function changeMarker(chart) { let preSet = [{ fill: "", shape: 0 /** circle */, size: 7, border: { color: "blue", width: 1 } }, { fill: "", shape: 8 /** star */, size: 9, border: { color: "black", width: 1 } }, { fill: "yellow", shape: 2 /** diamond */, size: 7, border: { color: "red", width: 2 } }, ]; let series = chart.series().get(); let seriesItem; for (let i = 0; i < series.length; i++) { seriesItem = series[i]; seriesItem.symbol = preSet[i]; chart.series().set(i, seriesItem); } } </script> <style scoped> .sample-tutorial { position: relative; height: 100%; overflow: hidden; } .sample-spreadsheets { width: 100%; height: 100%; overflow: hidden; float: left; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; } #app { height: 100%; } </style>
<!DOCTYPE html> <html style="height:100%;font-size:14px;"> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <title>SpreadJS VUE</title> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/en/vue3/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/en/vue3/node_modules/systemjs/dist/system.src.js"></script> <script src="./systemjs.config.js"></script> <script src="./compiler.js" type="module"></script> <script> var System = SystemJS; System.import("./src/app.js"); System.import('$DEMOROOT$/en/lib/vue3/license.js'); </script> </head> <body> <div id="app"></div> </body> </html>
(function (global) { SystemJS.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, packageConfigPaths: [ './node_modules/*/package.json', "./node_modules/@mescius/*/package.json", "./node_modules/@babel/*/package.json", "./node_modules/@vue/*/package.json" ], map: { 'vue': "npm:vue/dist/vue.esm-browser.js", 'tiny-emitter': 'npm:tiny-emitter/index.js', 'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js', "systemjs-babel-build": "npm:systemjs-plugin-babel/systemjs-babel-browser.js", '@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js', '@mescius/spread-sheets-resources-en': 'npm:@mescius/spread-sheets-resources-en/index.js', '@mescius/spread-sheets-vue': 'npm:@mescius/spread-sheets-vue/index.js', '@mescius/spread-sheets-shapes': 'npm:@mescius/spread-sheets-shapes/index.js', '@mescius/spread-sheets-charts': 'npm:@mescius/spread-sheets-charts/index.js', }, meta: { '*.css': { loader: 'systemjs-plugin-css' }, '*.vue': { loader: "../plugin-vue/index.js" } } }); })(this);