[]
        
(Showing Draft Content)

Line Charts

Line charts connect data points with lines to show how values change across categories or over time. They are commonly used to visualize trends, fluctuations, and directional movement in business, financial, and operational data.

SpreadJS allows you to customize line charts by modifying properties such as the color palette, line thickness, symbol display, tooltip style, and axis appearance, either through code or by using the Inspector tab in the SpreadJS Designer.

Note: The samples in this topic use the Sales table introduced in Bind Data Source. Ensure that the data source has been configured before adding a chart.

Line Chart

A basic line chart displays aggregated values across categories. Each data point is connected to illustrate the overall trend.

SpreadJS line Data Chart connects aggregated Sales values across product categories, with separate regional series helping developers compare business trends.

// Line Chart
const sheet = spread.getActiveSheet();
sheet.name("Line Chart");

const dataChart = sheet.dataCharts.add(
  'data-chart',
  10, 10, 600, 400
);

dataChart.setChartConfig({
  tableName: 'Sales',
  config: {
    header: {
      title: "Line Chart"
    }
  },
  plots: [{
    type: GC.Spread.Sheets.DataCharts.DataChartType.line,
    encodings: {
      category: { field: "Product" },
      details: [{ field: 'Region' }],
      color: { field: "Region" },
      values: [{
        field: "Sales",
        aggregate: GC.Spread.Sheets.DataCharts.Aggregate.sum
      }]
    },
    config: {
      axisMode: GC.Spread.Sheets.DataCharts.AxisMode.cartesian
    }
  }]
});

Line Chart with Hierarchical Category

Line charts support hierarchical category grouping.

category: {
  field: "ProductCategory",
  child: {
    field: "Product"
  }
}

The nesting order defines the grouping hierarchy.

SpreadJS line Data Chart groups the category axis by ProductCategory and nested Product fields, enabling developers to analyze trends within a hierarchy.

Line Aspect

Line charts support the lineAspect property, which controls how data points are connected and rendered.

Line Aspect

Sample

Default

SpreadJS line Data Chart uses the Default lineAspect property behavior to connect consecutive data points with straight line segments.

Spline

SpreadJS line Data Chart uses the Spline lineAspect property to connect data points with smooth curves for visualizing gradual trend changes.

StepCenter

SpreadJS line Data Chart applies the StepCenter lineAspect property, placing each vertical transition midway between adjacent category data points.

StepLeft

SpreadJS line Data Chart applies the StepLeft lineAspect property to render stepped series transitions aligned toward the left side of intervals.

StepRight

SpreadJS line Data Chart applies the StepRight lineAspect property to render stepped series transitions aligned toward the right side of intervals.

BezierCurve

SpreadJS line Data Chart uses the BezierCurve lineAspect property to create curved connections between data points for smoother trend presentation.

If lineAspect is set to null or undefined, the chart renders using the Default behavior.

Example

config: {
  lineAspect: GC.Spread.Sheets.DataCharts.LineAspect.Spline
}

Symbols and Line Style

Line charts allow customization of line thickness and symbol appearance.

config: {
  style: {
    strokeWidth: 2,
    symbolShape: GC.Spread.Sheets.DataCharts.SymbolShape.dot,
    symbolSize: 10
  },
  symbols: true
}
  • strokeWidth controls the thickness of the line.

  • symbolShape defines the marker shape.

  • symbolSize controls marker size.

  • symbols enables or disables symbol display.

SpreadJS line Data Chart displays thicker series lines with dot markers enabled through strokeWidth, symbolShape, symbolSize, and symbols properties.

Color Palette

The palette property defines the color sequence used for multiple series.

config: {
  palette: [
    "#88bde6",
    "#fbb258",
    "#90cd97",
    "#f6aac9",
    "#bfa554",
    "#bc99c7"
  ]
}

The palette is applied in order to the generated series.

SpreadJS line Data Chart applies a custom palette property to distinguish multiple generated series with an ordered sequence of colors.