Chart Area

Area charts are similar to line charts but with the area below the line filled in, making them ideal for showing volume or cumulative data.

Basic Usage

To visualize data with an area chart, use type: 'area'. Like line charts, area charts require both start and value.

await import('/components/data-display/chart.js');
const { tags, $ } = Lightview;
const { Chart } = tags;

const chart = Chart({ 
    type: 'area', 
    labels: true, 
    primaryAxis: true,
    style: 'width: 100%; max-width: 600px; height: 250px; margin: 0 auto;' 
},
    Chart.Body({},
        Chart.Row({}, Chart.Label({}, 'Jan'), Chart.Data({ start: 0.2, value: 0.4 })),
        Chart.Row({}, Chart.Label({}, 'Feb'), Chart.Data({ start: 0.4, value: 0.6 })),
        Chart.Row({}, Chart.Label({}, 'Mar'), Chart.Data({ start: 0.6, value: 0.5 })),
        Chart.Row({}, Chart.Label({}, 'Apr'), Chart.Data({ start: 0.5, value: 0.8 })),
        Chart.Row({}, Chart.Label({}, 'May'), Chart.Data({ start: 0.8, value: 0.7 }))
    )
);

$('#example').content(chart);
await import('/components/data-display/chart.js');
const { tags, $ } = Lightview;
const { Chart } = tags;

const months = [
    { label: 'Jan', start: 0.2, value: 0.4 },
    { label: 'Feb', start: 0.4, value: 0.6 },
    { label: 'Mar', start: 0.6, value: 0.5 },
    { label: 'Apr', start: 0.5, value: 0.8 },
    { label: 'May', start: 0.8, value: 0.7 }
];

const chart = {
    tag: Chart,
    attributes: { 
        type: 'area', 
        labels: true, 
        primaryAxis: true,
        style: 'width: 100%; max-width: 600px; height: 250px; margin: 0 auto;' 
    },
    children: [
        {
            tag: Chart.Body,
            children: months.map(m => ({
                tag: Chart.Row,
                children: [
                    { tag: Chart.Label, children: [m.label] },
                    { tag: Chart.Data, attributes: { start: m.start, value: m.value } }
                ]
            }))
        }
    ]
};

$('#example').content(chart);
await import('/components/data-display/chart.js');
const { $ } = Lightview;

const chart = {
    Chart: {
        type: 'area',
        labels: true,
        primaryAxis: true,
        style: 'width: 100%; max-width: 600px; height: 250px; margin: 0 auto;',
        children: [
            {
                'Chart.Body': {
                    children: [
                        { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['Jan'] } }, { 'Chart.Data': { start: 0.2, value: 0.4 } }] } },
                        { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['Feb'] } }, { 'Chart.Data': { start: 0.4, value: 0.6 } }] } },
                        { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['Mar'] } }, { 'Chart.Data': { start: 0.6, value: 0.5 } }] } },
                        { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['Apr'] } }, { 'Chart.Data': { start: 0.5, value: 0.8 } }] } },
                        { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['May'] } }, { 'Chart.Data': { start: 0.8, value: 0.7 } }] } }
                    ]
                }
            }
        ]
    }
};

$('#example').content(chart);

Multiple Datasets

Create layered areas with multiple datasets.

await import('/components/data-display/chart.js');
const { tags, $ } = Lightview;
const { Chart } = tags;

const chart = Chart({ 
    type: 'area', 
    multiple: true,
    labels: true, 
    primaryAxis: true,
    style: 'width: 100%; max-width: 600px; height: 280px; margin: 0 auto; --color-1: rgba(76, 175, 80, 0.5); --color-2: rgba(33, 150, 243, 0.5); --color-3: rgba(255, 152, 0, 0.5);' 
},
    Chart.Body({},
        Chart.Row({},
            Chart.Label({}, 'Q1'),
            Chart.Data({ start: 0.1, value: 0.3 }),
            Chart.Data({ start: 0.2, value: 0.4 }),
            Chart.Data({ start: 0.15, value: 0.35 })
        ),
        Chart.Row({},
            Chart.Label({}, 'Q2'),
            Chart.Data({ start: 0.3, value: 0.5 }),
            Chart.Data({ start: 0.4, value: 0.6 }),
            Chart.Data({ start: 0.35, value: 0.5 })
        ),
        Chart.Row({},
            Chart.Label({}, 'Q3'),
            Chart.Data({ start: 0.5, value: 0.4 }),
            Chart.Data({ start: 0.6, value: 0.5 }),
            Chart.Data({ start: 0.5, value: 0.6 })
        ),
        Chart.Row({},
            Chart.Label({}, 'Q4'),
            Chart.Data({ start: 0.4, value: 0.7 }),
            Chart.Data({ start: 0.5, value: 0.8 }),
            Chart.Data({ start: 0.6, value: 0.75 })
        )
    )
);

$('#example').content(chart);
await import('/components/data-display/chart.js');
const { tags, $ } = Lightview;
const { Chart } = tags;

const quarters = [
    { label: 'Q1', data: [[0.1, 0.3], [0.2, 0.4], [0.15, 0.35]] },
    { label: 'Q2', data: [[0.3, 0.5], [0.4, 0.6], [0.35, 0.5]] },
    { label: 'Q3', data: [[0.5, 0.4], [0.6, 0.5], [0.5, 0.6]] },
    { label: 'Q4', data: [[0.4, 0.7], [0.5, 0.8], [0.6, 0.75]] }
];

const chart = {
    tag: Chart,
    attributes: { 
        type: 'area', 
        multiple: true,
        labels: true, 
        primaryAxis: true,
        style: 'width: 100%; max-width: 600px; height: 280px; margin: 0 auto; --color-1: rgba(76, 175, 80, 0.5); --color-2: rgba(33, 150, 243, 0.5); --color-3: rgba(255, 152, 0, 0.5);' 
    },
    children: [
        {
            tag: Chart.Body,
            children: quarters.map(q => ({
                tag: Chart.Row,
                children: [
                    { tag: Chart.Label, children: [q.label] },
                    ...q.data.map(([start, value]) => ({
                        tag: Chart.Data,
                        attributes: { start, value }
                    }))
                ]
            }))
        }
    ]
};

$('#example').content(chart);
await import('/components/data-display/chart.js');
const { $ } = Lightview;

const chart = {
    Chart: {
        type: 'area',
        multiple: true,
        labels: true,
        primaryAxis: true,
        style: 'width: 100%; max-width: 600px; height: 280px; margin: 0 auto; --color-1: rgba(76, 175, 80, 0.5); --color-2: rgba(33, 150, 243, 0.5); --color-3: rgba(255, 152, 0, 0.5);',
        children: [
            {
                'Chart.Body': {
                    children: [
                        { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['Q1'] } }, { 'Chart.Data': { start: 0.1, value: 0.3 } }, { 'Chart.Data': { start: 0.2, value: 0.4 } }, { 'Chart.Data': { start: 0.15, value: 0.35 } }] } },
                        { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['Q2'] } }, { 'Chart.Data': { start: 0.3, value: 0.5 } }, { 'Chart.Data': { start: 0.4, value: 0.6 } }, { 'Chart.Data': { start: 0.35, value: 0.5 } }] } },
                        { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['Q3'] } }, { 'Chart.Data': { start: 0.5, value: 0.4 } }, { 'Chart.Data': { start: 0.6, value: 0.5 } }, { 'Chart.Data': { start: 0.5, value: 0.6 } }] } },
                        { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['Q4'] } }, { 'Chart.Data': { start: 0.4, value: 0.7 } }, { 'Chart.Data': { start: 0.5, value: 0.8 } }, { 'Chart.Data': { start: 0.6, value: 0.75 } }] } }
                    ]
                }
            }
        ]
    }
};

$('#example').content(chart);

Axes and Grid

Add grid lines with primaryAxis and secondaryAxis.

await import('/components/data-display/chart.js');
const { tags, $ } = Lightview;
const { Chart } = tags;

const chart = Chart({ 
    type: 'area', 
    labels: true, 
    primaryAxis: true,
    secondaryAxesCount: 4,
    style: 'width: 100%; max-width: 600px; height: 280px; margin: 0 auto;' 
},
    Chart.Body({},
        Chart.Row({}, Chart.Label({}, '1'), Chart.Data({ start: 0.0, value: 0.25 })),
        Chart.Row({}, Chart.Label({}, '2'), Chart.Data({ start: 0.25, value: 0.5 })),
        Chart.Row({}, Chart.Label({}, '3'), Chart.Data({ start: 0.5, value: 0.75 })),
        Chart.Row({}, Chart.Label({}, '4'), Chart.Data({ start: 0.75, value: 0.5 })),
        Chart.Row({}, Chart.Label({}, '5'), Chart.Data({ start: 0.5, value: 1.0 }))
    )
);

$('#example').content(chart);
await import('/components/data-display/chart.js');
const { tags, $ } = Lightview;
const { Chart } = tags;

const data = [
    [0.0, 0.25], [0.25, 0.5], [0.5, 0.75], 
    [0.75, 0.5], [0.5, 1.0]
];

const chart = {
    tag: Chart,
    attributes: { 
        type: 'area', 
        labels: true, 
        primaryAxis: true,
        secondaryAxesCount: 4,
        style: 'width: 100%; max-width: 600px; height: 280px; margin: 0 auto;' 
    },
    children: [
        {
            tag: Chart.Body,
            children: data.map(([start, value], i) => ({
                tag: Chart.Row,
                children: [
                    { tag: Chart.Label, children: [String(i + 1)] },
                    { tag: Chart.Data, attributes: { start, value } }
                ]
            }))
        }
    ]
};

$('#example').content(chart);
await import('/components/data-display/chart.js');
const { $ } = Lightview;

const chart = {
    Chart: {
        type: 'area',
        labels: true,
        primaryAxis: true,
        secondaryAxesCount: 4,
        style: 'width: 100%; max-width: 600px; height: 280px; margin: 0 auto;',
        children: [
            {
                'Chart.Body': {
                    children: [
                        { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['1'] } }, { 'Chart.Data': { start: 0.0, value: 0.25 } }] } },
                        { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['2'] } }, { 'Chart.Data': { start: 0.25, value: 0.5 } }] } },
                        { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['3'] } }, { 'Chart.Data': { start: 0.5, value: 0.75 } }] } },
                        { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['4'] } }, { 'Chart.Data': { start: 0.75, value: 0.5 } }] } },
                        { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['5'] } }, { 'Chart.Data': { start: 0.5, value: 1.0 } }] } }
                    ]
                }
            }
        ]
    }
};

$('#example').content(chart);

Area Styling

Customize area appearance with CSS custom properties.

await import('/components/data-display/chart.js');
const { tags, $ } = Lightview;
const { Chart } = tags;

const chart = Chart({ 
    type: 'area', 
    labels: true,
    style: 'width: 100%; max-width: 600px; height: 250px; margin: 0 auto; --color: rgba(116, 128, 255, 0.6);' 
},
    Chart.Body({},
        Chart.Row({}, Chart.Label({}, 'Mon'), Chart.Data({ start: 0.2, value: 0.5 })),
        Chart.Row({}, Chart.Label({}, 'Tue'), Chart.Data({ start: 0.5, value: 0.7 })),
        Chart.Row({}, Chart.Label({}, 'Wed'), Chart.Data({ start: 0.7, value: 0.4 })),
        Chart.Row({}, Chart.Label({}, 'Thu'), Chart.Data({ start: 0.4, value: 0.8 })),
        Chart.Row({}, Chart.Label({}, 'Fri'), Chart.Data({ start: 0.8, value: 0.6 }))
    )
);

$('#example').content(chart);
await import('/components/data-display/chart.js');
const { tags, $ } = Lightview;
const { Chart } = tags;

const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'];
const data = [[0.2, 0.5], [0.5, 0.7], [0.7, 0.4], [0.4, 0.8], [0.8, 0.6]];

const chart = {
    tag: Chart,
    attributes: { 
        type: 'area', 
        labels: true,
        style: 'width: 100%; max-width: 600px; height: 250px; margin: 0 auto; --color: rgba(116, 128, 255, 0.6);' 
    },
    children: [
        {
            tag: Chart.Body,
            children: days.map((day, i) => ({
                tag: Chart.Row,
                children: [
                    { tag: Chart.Label, children: [day] },
                    { tag: Chart.Data, attributes: { start: data[i][0], value: data[i][1] } }
                ]
            }))
        }
    ]
};

$('#example').content(chart);
await import('/components/data-display/chart.js');
const { $ } = Lightview;

const chart = {
    Chart: {
        type: 'area',
        labels: true,
        style: 'width: 100%; max-width: 600px; height: 250px; margin: 0 auto; --color: rgba(116, 128, 255, 0.6);',
        children: [
            {
                'Chart.Body': {
                    children: [
                        { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['Mon'] } }, { 'Chart.Data': { start: 0.2, value: 0.5 } }] } },
                        { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['Tue'] } }, { 'Chart.Data': { start: 0.5, value: 0.7 } }] } },
                        { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['Wed'] } }, { 'Chart.Data': { start: 0.7, value: 0.4 } }] } },
                        { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['Thu'] } }, { 'Chart.Data': { start: 0.4, value: 0.8 } }] } },
                        { 'Chart.Row': { children: [{ 'Chart.Label': { children: ['Fri'] } }, { 'Chart.Data': { start: 0.8, value: 0.6 } }] } }
                    ]
                }
            }
        ]
    }
};

$('#example').content(chart);