내장 꺾은선 스파크The built-in line sparkline
cellRenderer 'sparkline'은 숫자 배열을 칸 안의 작은 꺾은선으로 그려요. curve로 곡선, area로 영역, marks로 표시 점, tone으로 색을 정해요. 직접 만든 렌더러 없이도 접근 이름과 어두운 모드가 따라와요.cellRenderer 'sparkline' draws an array of numbers as a small line in the cell. curve makes it smooth, area fills below it, marks picks the dots and tone sets the color. Without a custom renderer you still get an accessible name and dark mode.
코드Code
탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.
이 화면은 새 모양 옵션을 켠 모양이에요: density: 'spacious', iconStyle: 'soft', motion: true (코드에 없으면 기본 모양으로 보여요)This preview has the new-look options on: density: 'spacious', iconStyle: 'soft', motion: true (without them in your code you get the default look)
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<div id="app">
<div class="toolbar">
<select aria-label="곡선" id="curve">
<option value="linear" selected>꺾은선</option>
<option value="smooth">곡선</option>
</select>
<select aria-label="영역" id="area">
<option value="off" selected>없음</option>
<option value="on">채움</option>
</select>
<select aria-label="표시 점" id="marks">
<option value="last" selected>마지막</option>
<option value="ends">처음·끝</option>
<option value="extremes">최소·최대</option>
</select>
<button type="button" id="add">값 더하기</button>
</div>
<div id="grid" style="height: 300px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('curve').addEventListener('change', (event) => actions.curve(api, event.target.value));
document.getElementById('area').addEventListener('change', (event) => actions.area(api, event.target.value));
document.getElementById('marks').addEventListener('change', (event) => actions.marks(api, event.target.value));
document.getElementById('add').addEventListener('click', () => actions.add(api));const initial = () => [
{ id: 1, name: '한빛전자', trend: [68, 69, 67, 70, 72, 71, 74] },
{ id: 2, name: '파란에너지', trend: [44, 43, 45, 41, 40, 39, 38] },
{ id: 3, name: '단풍제약', trend: [110, 112, 118, 117, 121, 123, 125] },
{ id: 4, name: '새로 상장', trend: [10] },
];
// sparkline은 셀 값(숫자 배열)을 그대로 그려요. curve: 'smooth', area: true, marks: 점 자리, tone: 색, min·max: 축 고정.
const state = {
curve: 'linear',
area: false,
marks: ['last'],
};
const columns = () => [
{ id: 'name', title: '종목', width: 140 },
{
id: 'trend',
title: '최근 7일',
width: 220,
cellRenderer: 'sparkline',
cellRendererParams: { curve: state.curve, area: state.area, marks: state.marks, height: 22 },
},
];
let rows = initial();
export const options = { columns: columns(), rows, rowKey: 'id' };
const apply = (api) => api.setColumns(columns());
export const actions = {
curve: (api, value) => {
state.curve = value === 'smooth' ? 'smooth' : 'linear';
apply(api);
},
area: (api, value) => {
state.area = value === 'on';
apply(api);
},
marks: (api, value) => {
state.marks =
value === 'ends' ? ['first', 'last'] : value === 'extremes' ? ['min', 'max'] : ['last'];
apply(api);
},
add: (api) => {
rows = rows.map((row, i) => ({
...row,
trend: [
...row.trend,
Math.max(1, (row.trend[row.trend.length - 1] ?? 10) + ((i * 7 + row.trend.length * 3) % 9) - 4),
],
}));
api.setRows(rows);
},
};
export function setup(_api, log) {
log({
ko: '"곡선", "영역", "표시 점"을 바꾸고 "값 더하기"로 점을 늘려 보세요. 마지막 줄은 점이 하나뿐이라 줄표예요.',
en: 'Change "Curve", "Area" and "Dots", and use "Add value" to grow the series. The last row has one point so it shows a dash.',
});
}<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>내장 꺾은선 스파크</title>
</head>
<body>
<div class="toolbar">
<select aria-label="곡선" id="curve">
<option value="linear" selected>꺾은선</option>
<option value="smooth">곡선</option>
</select>
<select aria-label="영역" id="area">
<option value="off" selected>없음</option>
<option value="on">채움</option>
</select>
<select aria-label="표시 점" id="marks">
<option value="last" selected>마지막</option>
<option value="ends">처음·끝</option>
<option value="extremes">최소·최대</option>
</select>
<button type="button" id="add">값 더하기</button>
</div>
<div id="grid" style="height: 300px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const initial = () => [
{ id: 1, name: '한빛전자', trend: [68, 69, 67, 70, 72, 71, 74] },
{ id: 2, name: '파란에너지', trend: [44, 43, 45, 41, 40, 39, 38] },
{ id: 3, name: '단풍제약', trend: [110, 112, 118, 117, 121, 123, 125] },
{ id: 4, name: '새로 상장', trend: [10] },
];
// sparkline은 셀 값(숫자 배열)을 그대로 그려요. curve: 'smooth', area: true, marks: 점 자리, tone: 색, min·max: 축 고정.
const state = {
curve: 'linear',
area: false,
marks: ['last'],
};
const columns = () => [
{ id: 'name', title: '종목', width: 140 },
{
id: 'trend',
title: '최근 7일',
width: 220,
cellRenderer: 'sparkline',
cellRendererParams: { curve: state.curve, area: state.area, marks: state.marks, height: 22 },
},
];
let rows = initial();
const options = { columns: columns(), rows, rowKey: 'id' };
const apply = (api) => api.setColumns(columns());
const actions = {
curve: (api, value) => {
state.curve = value === 'smooth' ? 'smooth' : 'linear';
apply(api);
},
area: (api, value) => {
state.area = value === 'on';
apply(api);
},
marks: (api, value) => {
state.marks =
value === 'ends' ? ['first', 'last'] : value === 'extremes' ? ['min', 'max'] : ['last'];
apply(api);
},
add: (api) => {
rows = rows.map((row, i) => ({
...row,
trend: [
...row.trend,
Math.max(1, (row.trend[row.trend.length - 1] ?? 10) + ((i * 7 + row.trend.length * 3) % 9) - 4),
],
}));
api.setRows(rows);
},
};
function setup(_api, log) {
log({
ko: '"곡선", "영역", "표시 점"을 바꾸고 "값 더하기"로 점을 늘려 보세요. 마지막 줄은 점이 하나뿐이라 줄표예요.',
en: 'Change "Curve", "Area" and "Dots", and use "Add value" to grow the series. The last row has one point so it shows a dash.',
});
}
options.ariaLabel = "내장 꺾은선 스파크";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('curve').addEventListener('change', (event) => actions.curve(api, event.target.value));
document.getElementById('area').addEventListener('change', (event) => actions.area(api, event.target.value));
document.getElementById('marks').addEventListener('change', (event) => actions.marks(api, event.target.value));
document.getElementById('add').addEventListener('click', () => actions.add(api));
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="곡선"
disabled={!api}
onChange={(event) => api && actions.curve(api, event.target.value)}
>
<option value="linear">꺾은선</option>
<option value="smooth">곡선</option>
</select>
<select defaultValue="linear"
aria-label="영역"
disabled={!api}
onChange={(event) => api && actions.area(api, event.target.value)}
>
<option value="off">없음</option>
<option value="on">채움</option>
</select>
<select defaultValue="off"
aria-label="표시 점"
disabled={!api}
onChange={(event) => api && actions.marks(api, event.target.value)}
>
<option value="last">마지막</option>
<option value="ends">처음·끝</option>
<option value="extremes">최소·최대</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.add(api)}
>값 더하기</button>
</div>
<Grid style={{ height: 300 }} ref={gridRef} options={options} />
</>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
trend: number[];
}
const initial = (): Row[] => [
{ id: 1, name: '한빛전자', trend: [68, 69, 67, 70, 72, 71, 74] },
{ id: 2, name: '파란에너지', trend: [44, 43, 45, 41, 40, 39, 38] },
{ id: 3, name: '단풍제약', trend: [110, 112, 118, 117, 121, 123, 125] },
{ id: 4, name: '새로 상장', trend: [10] },
];
// sparkline은 셀 값(숫자 배열)을 그대로 그려요. curve: 'smooth', area: true, marks: 점 자리, tone: 색, min·max: 축 고정.
const state = {
curve: 'linear' as 'linear' | 'smooth',
area: false,
marks: ['last'] as Array<'first' | 'last' | 'min' | 'max'>,
};
const columns = (): ColumnDef<Row>[] => [
{ id: 'name', title: '종목', width: 140 },
{
id: 'trend',
title: '최근 7일',
width: 220,
cellRenderer: 'sparkline',
cellRendererParams: { curve: state.curve, area: state.area, marks: state.marks, height: 22 },
},
];
let rows = initial();
export const options: GridOptions<Row> = { columns: columns(), rows, rowKey: 'id' };
const apply = (api: GridApi<Row>): void => api.setColumns(columns());
export const actions = {
curve: (api: GridApi<Row>, value?: string) => {
state.curve = value === 'smooth' ? 'smooth' : 'linear';
apply(api);
},
area: (api: GridApi<Row>, value?: string) => {
state.area = value === 'on';
apply(api);
},
marks: (api: GridApi<Row>, value?: string) => {
state.marks =
value === 'ends' ? ['first', 'last'] : value === 'extremes' ? ['min', 'max'] : ['last'];
apply(api);
},
add: (api: GridApi<Row>) => {
rows = rows.map((row, i) => ({
...row,
trend: [
...row.trend,
Math.max(
1,
(row.trend[row.trend.length - 1] ?? 10) + ((i * 7 + row.trend.length * 3) % 9) - 4,
),
],
}));
api.setRows(rows);
},
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"곡선", "영역", "표시 점"을 바꾸고 "값 더하기"로 점을 늘려 보세요. 마지막 줄은 점이 하나뿐이라 줄표예요.',
en: 'Change "Curve", "Area" and "Dots", and use "Add value" to grow the series. The last row has one point so it shows a dash.',
});
}버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<select
aria-label="곡선"
:disabled="!api"
@change="api && actions.curve(api, ($event.target as HTMLSelectElement).value)"
>
<option value="linear" selected>꺾은선</option>
<option value="smooth">곡선</option>
</select>
<select
aria-label="영역"
:disabled="!api"
@change="api && actions.area(api, ($event.target as HTMLSelectElement).value)"
>
<option value="off" selected>없음</option>
<option value="on">채움</option>
</select>
<select
aria-label="표시 점"
:disabled="!api"
@change="api && actions.marks(api, ($event.target as HTMLSelectElement).value)"
>
<option value="last" selected>마지막</option>
<option value="ends">처음·끝</option>
<option value="extremes">최소·최대</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.add(api)">값 더하기</button>
</div>
<Grid style="height: 300px" :options="options" @ready="onReady" />
</template>import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
trend: number[];
}
const initial = (): Row[] => [
{ id: 1, name: '한빛전자', trend: [68, 69, 67, 70, 72, 71, 74] },
{ id: 2, name: '파란에너지', trend: [44, 43, 45, 41, 40, 39, 38] },
{ id: 3, name: '단풍제약', trend: [110, 112, 118, 117, 121, 123, 125] },
{ id: 4, name: '새로 상장', trend: [10] },
];
// sparkline은 셀 값(숫자 배열)을 그대로 그려요. curve: 'smooth', area: true, marks: 점 자리, tone: 색, min·max: 축 고정.
const state = {
curve: 'linear' as 'linear' | 'smooth',
area: false,
marks: ['last'] as Array<'first' | 'last' | 'min' | 'max'>,
};
const columns = (): ColumnDef<Row>[] => [
{ id: 'name', title: '종목', width: 140 },
{
id: 'trend',
title: '최근 7일',
width: 220,
cellRenderer: 'sparkline',
cellRendererParams: { curve: state.curve, area: state.area, marks: state.marks, height: 22 },
},
];
let rows = initial();
export const options: GridOptions<Row> = { columns: columns(), rows, rowKey: 'id' };
const apply = (api: GridApi<Row>): void => api.setColumns(columns());
export const actions = {
curve: (api: GridApi<Row>, value?: string) => {
state.curve = value === 'smooth' ? 'smooth' : 'linear';
apply(api);
},
area: (api: GridApi<Row>, value?: string) => {
state.area = value === 'on';
apply(api);
},
marks: (api: GridApi<Row>, value?: string) => {
state.marks =
value === 'ends' ? ['first', 'last'] : value === 'extremes' ? ['min', 'max'] : ['last'];
apply(api);
},
add: (api: GridApi<Row>) => {
rows = rows.map((row, i) => ({
...row,
trend: [
...row.trend,
Math.max(
1,
(row.trend[row.trend.length - 1] ?? 10) + ((i * 7 + row.trend.length * 3) % 9) - 4,
),
],
}));
api.setRows(rows);
},
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"곡선", "영역", "표시 점"을 바꾸고 "값 더하기"로 점을 늘려 보세요. 마지막 줄은 점이 하나뿐이라 줄표예요.',
en: 'Change "Curve", "Area" and "Dots", and use "Add value" to grow the series. The last row has one point so it shows a dash.',
});
}버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="곡선"
[disabled]="!api"
(change)="api && actions.curve(api, $any($event.target).value)"
>
<option value="linear" selected>꺾은선</option>
<option value="smooth">곡선</option>
</select>
<select
aria-label="영역"
[disabled]="!api"
(change)="api && actions.area(api, $any($event.target).value)"
>
<option value="off" selected>없음</option>
<option value="on">채움</option>
</select>
<select
aria-label="표시 점"
[disabled]="!api"
(change)="api && actions.marks(api, $any($event.target).value)"
>
<option value="last" selected>마지막</option>
<option value="ends">처음·끝</option>
<option value="extremes">최소·최대</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.add(api)"
>값 더하기</button>
</div>
<mx-grid style="height: 300px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
trend: number[];
}
const initial = (): Row[] => [
{ id: 1, name: '한빛전자', trend: [68, 69, 67, 70, 72, 71, 74] },
{ id: 2, name: '파란에너지', trend: [44, 43, 45, 41, 40, 39, 38] },
{ id: 3, name: '단풍제약', trend: [110, 112, 118, 117, 121, 123, 125] },
{ id: 4, name: '새로 상장', trend: [10] },
];
// sparkline은 셀 값(숫자 배열)을 그대로 그려요. curve: 'smooth', area: true, marks: 점 자리, tone: 색, min·max: 축 고정.
const state = {
curve: 'linear' as 'linear' | 'smooth',
area: false,
marks: ['last'] as Array<'first' | 'last' | 'min' | 'max'>,
};
const columns = (): ColumnDef<Row>[] => [
{ id: 'name', title: '종목', width: 140 },
{
id: 'trend',
title: '최근 7일',
width: 220,
cellRenderer: 'sparkline',
cellRendererParams: { curve: state.curve, area: state.area, marks: state.marks, height: 22 },
},
];
let rows = initial();
export const options: GridOptions<Row> = { columns: columns(), rows, rowKey: 'id' };
const apply = (api: GridApi<Row>): void => api.setColumns(columns());
export const actions = {
curve: (api: GridApi<Row>, value?: string) => {
state.curve = value === 'smooth' ? 'smooth' : 'linear';
apply(api);
},
area: (api: GridApi<Row>, value?: string) => {
state.area = value === 'on';
apply(api);
},
marks: (api: GridApi<Row>, value?: string) => {
state.marks =
value === 'ends' ? ['first', 'last'] : value === 'extremes' ? ['min', 'max'] : ['last'];
apply(api);
},
add: (api: GridApi<Row>) => {
rows = rows.map((row, i) => ({
...row,
trend: [
...row.trend,
Math.max(
1,
(row.trend[row.trend.length - 1] ?? 10) + ((i * 7 + row.trend.length * 3) % 9) - 4,
),
],
}));
api.setRows(rows);
},
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"곡선", "영역", "표시 점"을 바꾸고 "값 더하기"로 점을 늘려 보세요. 마지막 줄은 점이 하나뿐이라 줄표예요.',
en: 'Change "Curve", "Area" and "Dots", and use "Add value" to grow the series. The last row has one point so it shows a dash.',
});
}When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<select aria-label="Curve" id="curve">
<option value="linear" selected>Linear</option>
<option value="smooth">Smooth</option>
</select>
<select aria-label="Area" id="area">
<option value="off" selected>Off</option>
<option value="on">On</option>
</select>
<select aria-label="Dots" id="marks">
<option value="last" selected>Last</option>
<option value="ends">First and last</option>
<option value="extremes">Min and max</option>
</select>
<button type="button" id="add">Add value</button>
</div>
<div id="grid" style="height: 300px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('curve').addEventListener('change', (event) => actions.curve(api, event.target.value));
document.getElementById('area').addEventListener('change', (event) => actions.area(api, event.target.value));
document.getElementById('marks').addEventListener('change', (event) => actions.marks(api, event.target.value));
document.getElementById('add').addEventListener('click', () => actions.add(api));const initial = () => [
{ id: 1, name: 'Bright Electronics', trend: [68, 69, 67, 70, 72, 71, 74] },
{ id: 2, name: 'Blue Energy', trend: [44, 43, 45, 41, 40, 39, 38] },
{ id: 3, name: 'Maple Pharma', trend: [110, 112, 118, 117, 121, 123, 125] },
{ id: 4, name: 'New Listing', trend: [10] },
];
// sparkline draws the cell value (an array of numbers) as is. curve: 'smooth', area: true, marks: dot positions, tone: color, min/max: fixed axis.
const state = {
curve: 'linear',
area: false,
marks: ['last'],
};
const columns = () => [
{ id: 'name', title: 'Stock', width: 140 },
{
id: 'trend',
title: 'Last 7 days',
width: 220,
cellRenderer: 'sparkline',
cellRendererParams: { curve: state.curve, area: state.area, marks: state.marks, height: 22 },
},
];
let rows = initial();
export const options = { columns: columns(), rows, rowKey: 'id' };
const apply = (api) => api.setColumns(columns());
export const actions = {
curve: (api, value) => {
state.curve = value === 'smooth' ? 'smooth' : 'linear';
apply(api);
},
area: (api, value) => {
state.area = value === 'on';
apply(api);
},
marks: (api, value) => {
state.marks =
value === 'ends' ? ['first', 'last'] : value === 'extremes' ? ['min', 'max'] : ['last'];
apply(api);
},
add: (api) => {
rows = rows.map((row, i) => ({
...row,
trend: [
...row.trend,
Math.max(1, (row.trend[row.trend.length - 1] ?? 10) + ((i * 7 + row.trend.length * 3) % 9) - 4),
],
}));
api.setRows(rows);
},
};
export function setup(_api, log) {
log('Change "Curve", "Area" and "Dots", and use "Add value" to grow the series. The last row has one point so it shows a dash.');
}<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>The built-in line sparkline</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Curve" id="curve">
<option value="linear" selected>Linear</option>
<option value="smooth">Smooth</option>
</select>
<select aria-label="Area" id="area">
<option value="off" selected>Off</option>
<option value="on">On</option>
</select>
<select aria-label="Dots" id="marks">
<option value="last" selected>Last</option>
<option value="ends">First and last</option>
<option value="extremes">Min and max</option>
</select>
<button type="button" id="add">Add value</button>
</div>
<div id="grid" style="height: 300px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const initial = () => [
{ id: 1, name: 'Bright Electronics', trend: [68, 69, 67, 70, 72, 71, 74] },
{ id: 2, name: 'Blue Energy', trend: [44, 43, 45, 41, 40, 39, 38] },
{ id: 3, name: 'Maple Pharma', trend: [110, 112, 118, 117, 121, 123, 125] },
{ id: 4, name: 'New Listing', trend: [10] },
];
// sparkline draws the cell value (an array of numbers) as is. curve: 'smooth', area: true, marks: dot positions, tone: color, min/max: fixed axis.
const state = {
curve: 'linear',
area: false,
marks: ['last'],
};
const columns = () => [
{ id: 'name', title: 'Stock', width: 140 },
{
id: 'trend',
title: 'Last 7 days',
width: 220,
cellRenderer: 'sparkline',
cellRendererParams: { curve: state.curve, area: state.area, marks: state.marks, height: 22 },
},
];
let rows = initial();
const options = { columns: columns(), rows, rowKey: 'id' };
const apply = (api) => api.setColumns(columns());
const actions = {
curve: (api, value) => {
state.curve = value === 'smooth' ? 'smooth' : 'linear';
apply(api);
},
area: (api, value) => {
state.area = value === 'on';
apply(api);
},
marks: (api, value) => {
state.marks =
value === 'ends' ? ['first', 'last'] : value === 'extremes' ? ['min', 'max'] : ['last'];
apply(api);
},
add: (api) => {
rows = rows.map((row, i) => ({
...row,
trend: [
...row.trend,
Math.max(1, (row.trend[row.trend.length - 1] ?? 10) + ((i * 7 + row.trend.length * 3) % 9) - 4),
],
}));
api.setRows(rows);
},
};
function setup(_api, log) {
log('Change "Curve", "Area" and "Dots", and use "Add value" to grow the series. The last row has one point so it shows a dash.');
}
options.ariaLabel = "The built-in line sparkline";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('curve').addEventListener('change', (event) => actions.curve(api, event.target.value));
document.getElementById('area').addEventListener('change', (event) => actions.area(api, event.target.value));
document.getElementById('marks').addEventListener('change', (event) => actions.marks(api, event.target.value));
document.getElementById('add').addEventListener('click', () => actions.add(api));
</script>
</body>
</html>When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="Curve"
disabled={!api}
onChange={(event) => api && actions.curve(api, event.target.value)}
>
<option value="linear">Linear</option>
<option value="smooth">Smooth</option>
</select>
<select defaultValue="linear"
aria-label="Area"
disabled={!api}
onChange={(event) => api && actions.area(api, event.target.value)}
>
<option value="off">Off</option>
<option value="on">On</option>
</select>
<select defaultValue="off"
aria-label="Dots"
disabled={!api}
onChange={(event) => api && actions.marks(api, event.target.value)}
>
<option value="last">Last</option>
<option value="ends">First and last</option>
<option value="extremes">Min and max</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.add(api)}
>Add value</button>
</div>
<Grid style={{ height: 300 }} ref={gridRef} options={options} />
</>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
trend: number[];
}
const initial = (): Row[] => [
{ id: 1, name: 'Bright Electronics', trend: [68, 69, 67, 70, 72, 71, 74] },
{ id: 2, name: 'Blue Energy', trend: [44, 43, 45, 41, 40, 39, 38] },
{ id: 3, name: 'Maple Pharma', trend: [110, 112, 118, 117, 121, 123, 125] },
{ id: 4, name: 'New Listing', trend: [10] },
];
// sparkline draws the cell value (an array of numbers) as is. curve: 'smooth', area: true, marks: dot positions, tone: color, min/max: fixed axis.
const state = {
curve: 'linear' as 'linear' | 'smooth',
area: false,
marks: ['last'] as Array<'first' | 'last' | 'min' | 'max'>,
};
const columns = (): ColumnDef<Row>[] => [
{ id: 'name', title: 'Stock', width: 140 },
{
id: 'trend',
title: 'Last 7 days',
width: 220,
cellRenderer: 'sparkline',
cellRendererParams: { curve: state.curve, area: state.area, marks: state.marks, height: 22 },
},
];
let rows = initial();
export const options: GridOptions<Row> = { columns: columns(), rows, rowKey: 'id' };
const apply = (api: GridApi<Row>): void => api.setColumns(columns());
export const actions = {
curve: (api: GridApi<Row>, value?: string) => {
state.curve = value === 'smooth' ? 'smooth' : 'linear';
apply(api);
},
area: (api: GridApi<Row>, value?: string) => {
state.area = value === 'on';
apply(api);
},
marks: (api: GridApi<Row>, value?: string) => {
state.marks =
value === 'ends' ? ['first', 'last'] : value === 'extremes' ? ['min', 'max'] : ['last'];
apply(api);
},
add: (api: GridApi<Row>) => {
rows = rows.map((row, i) => ({
...row,
trend: [
...row.trend,
Math.max(
1,
(row.trend[row.trend.length - 1] ?? 10) + ((i * 7 + row.trend.length * 3) % 9) - 4,
),
],
}));
api.setRows(rows);
},
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Change "Curve", "Area" and "Dots", and use "Add value" to grow the series. The last row has one point so it shows a dash.',
);
}When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<select
aria-label="Curve"
:disabled="!api"
@change="api && actions.curve(api, ($event.target as HTMLSelectElement).value)"
>
<option value="linear" selected>Linear</option>
<option value="smooth">Smooth</option>
</select>
<select
aria-label="Area"
:disabled="!api"
@change="api && actions.area(api, ($event.target as HTMLSelectElement).value)"
>
<option value="off" selected>Off</option>
<option value="on">On</option>
</select>
<select
aria-label="Dots"
:disabled="!api"
@change="api && actions.marks(api, ($event.target as HTMLSelectElement).value)"
>
<option value="last" selected>Last</option>
<option value="ends">First and last</option>
<option value="extremes">Min and max</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.add(api)">Add value</button>
</div>
<Grid style="height: 300px" :options="options" @ready="onReady" />
</template>import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
trend: number[];
}
const initial = (): Row[] => [
{ id: 1, name: 'Bright Electronics', trend: [68, 69, 67, 70, 72, 71, 74] },
{ id: 2, name: 'Blue Energy', trend: [44, 43, 45, 41, 40, 39, 38] },
{ id: 3, name: 'Maple Pharma', trend: [110, 112, 118, 117, 121, 123, 125] },
{ id: 4, name: 'New Listing', trend: [10] },
];
// sparkline draws the cell value (an array of numbers) as is. curve: 'smooth', area: true, marks: dot positions, tone: color, min/max: fixed axis.
const state = {
curve: 'linear' as 'linear' | 'smooth',
area: false,
marks: ['last'] as Array<'first' | 'last' | 'min' | 'max'>,
};
const columns = (): ColumnDef<Row>[] => [
{ id: 'name', title: 'Stock', width: 140 },
{
id: 'trend',
title: 'Last 7 days',
width: 220,
cellRenderer: 'sparkline',
cellRendererParams: { curve: state.curve, area: state.area, marks: state.marks, height: 22 },
},
];
let rows = initial();
export const options: GridOptions<Row> = { columns: columns(), rows, rowKey: 'id' };
const apply = (api: GridApi<Row>): void => api.setColumns(columns());
export const actions = {
curve: (api: GridApi<Row>, value?: string) => {
state.curve = value === 'smooth' ? 'smooth' : 'linear';
apply(api);
},
area: (api: GridApi<Row>, value?: string) => {
state.area = value === 'on';
apply(api);
},
marks: (api: GridApi<Row>, value?: string) => {
state.marks =
value === 'ends' ? ['first', 'last'] : value === 'extremes' ? ['min', 'max'] : ['last'];
apply(api);
},
add: (api: GridApi<Row>) => {
rows = rows.map((row, i) => ({
...row,
trend: [
...row.trend,
Math.max(
1,
(row.trend[row.trend.length - 1] ?? 10) + ((i * 7 + row.trend.length * 3) % 9) - 4,
),
],
}));
api.setRows(rows);
},
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Change "Curve", "Area" and "Dots", and use "Add value" to grow the series. The last row has one point so it shows a dash.',
);
}When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="Curve"
[disabled]="!api"
(change)="api && actions.curve(api, $any($event.target).value)"
>
<option value="linear" selected>Linear</option>
<option value="smooth">Smooth</option>
</select>
<select
aria-label="Area"
[disabled]="!api"
(change)="api && actions.area(api, $any($event.target).value)"
>
<option value="off" selected>Off</option>
<option value="on">On</option>
</select>
<select
aria-label="Dots"
[disabled]="!api"
(change)="api && actions.marks(api, $any($event.target).value)"
>
<option value="last" selected>Last</option>
<option value="ends">First and last</option>
<option value="extremes">Min and max</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.add(api)"
>Add value</button>
</div>
<mx-grid style="height: 300px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
trend: number[];
}
const initial = (): Row[] => [
{ id: 1, name: 'Bright Electronics', trend: [68, 69, 67, 70, 72, 71, 74] },
{ id: 2, name: 'Blue Energy', trend: [44, 43, 45, 41, 40, 39, 38] },
{ id: 3, name: 'Maple Pharma', trend: [110, 112, 118, 117, 121, 123, 125] },
{ id: 4, name: 'New Listing', trend: [10] },
];
// sparkline draws the cell value (an array of numbers) as is. curve: 'smooth', area: true, marks: dot positions, tone: color, min/max: fixed axis.
const state = {
curve: 'linear' as 'linear' | 'smooth',
area: false,
marks: ['last'] as Array<'first' | 'last' | 'min' | 'max'>,
};
const columns = (): ColumnDef<Row>[] => [
{ id: 'name', title: 'Stock', width: 140 },
{
id: 'trend',
title: 'Last 7 days',
width: 220,
cellRenderer: 'sparkline',
cellRendererParams: { curve: state.curve, area: state.area, marks: state.marks, height: 22 },
},
];
let rows = initial();
export const options: GridOptions<Row> = { columns: columns(), rows, rowKey: 'id' };
const apply = (api: GridApi<Row>): void => api.setColumns(columns());
export const actions = {
curve: (api: GridApi<Row>, value?: string) => {
state.curve = value === 'smooth' ? 'smooth' : 'linear';
apply(api);
},
area: (api: GridApi<Row>, value?: string) => {
state.area = value === 'on';
apply(api);
},
marks: (api: GridApi<Row>, value?: string) => {
state.marks =
value === 'ends' ? ['first', 'last'] : value === 'extremes' ? ['min', 'max'] : ['last'];
apply(api);
},
add: (api: GridApi<Row>) => {
rows = rows.map((row, i) => ({
...row,
trend: [
...row.trend,
Math.max(
1,
(row.trend[row.trend.length - 1] ?? 10) + ((i * 7 + row.trend.length * 3) % 9) - 4,
),
],
}));
api.setRows(rows);
},
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Change "Curve", "Area" and "Dots", and use "Add value" to grow the series. The last row has one point so it shows a dash.',
);
}