-
AI-powered Extensions
-
Data Grid
-
Tree List
-
Chat
-
HTML Editor
-
Form
-
-
Data Grids / Data Management
-
Data Grid
- Overview
-
Data Binding
-
Filtering
- Sorting
-
Editing
-
Grouping
-
Selection
- Focused Row
- Paging
-
Scrolling
-
Columns
- AI Assistant
-
Master-Detail
-
Data Summaries
-
Drag & Drop
-
Export to PDF
-
Export to Excel
- Appearance
-
Customization
- State Persistence
-
Adaptability
-
Keyboard Navigation
- Right-To-Left Support
-
Tree List
- Overview
-
Data Binding
-
Filtering
- Sorting
-
Editing
-
Selection
- Focused Row
- Paging
-
Columns
- Drag & Drop
- State Persistence
- Adaptability
-
Keyboard Navigation
-
Card View
-
Pivot Grid
- Overview
-
Data Binding
-
Field Management
-
Data Summaries
- Drill Down
- Filtering
-
Scrolling
-
Export to Excel
- Chart Integration
- Customization
- State Persistence
-
Filter Builder
-
-
Data Visualization
-
Charts
- Overview
-
Data Binding
-
Common Concepts
-
Axis
-
Aggregation
-
Tooltips
-
Selection
-
Customization
-
Zooming
-
Export
-
-
Area Charts
-
Bar Charts
- Bullet Charts
-
Doughnut Charts
-
Financial Charts
-
Funnel and Pyramid Charts
-
Line Charts
- Pareto Chart
-
Pie Charts
-
Point Charts
-
Polar and Radar Charts
-
Range Charts
- Sankey Chart
-
Sparkline Charts
-
Tree Map
-
Gauges
- Overview
-
Runtime update
-
Bar Gauge
-
Circular Gauge
-
Linear Gauge
-
Diagram
- Overview
-
Data Binding
-
Featured Shapes
-
Custom Shapes
-
Document Capabilities
-
User Interaction
- UI Customization
- Adaptability
-
-
Scheduling / Planning
-
Scheduler
- Overview
-
Data Binding
-
Views
-
Appointments
-
Timetable
- Editing
-
Grouping
- Virtual Scrolling
- Drag & Drop
-
Customization
- Adaptability
-
Gantt
- Overview
- Data Binding
-
Filtering
- Sorting
- Strip Lines
- Export to PDF
- Validation
-
Customization
-
-
Messaging
-
WYSIWYG Editor
-
Forms
-
Data Editors
- Overview
-
Common Concepts
-
Calendar
- Check Box
- Color Box
-
Date Box
-
Date Range Box
-
Number Box
- Radio Group
-
Range Selector
- Range Slider
- Slider
- Switch
- Text Area
- Text Box
-
Drop-Downs
- Autocomplete
-
Drop Down Box
-
Select Box
-
Tag Box
-
Lookup
-
Buttons
-
File Upload / File Management
-
File Manager
- Overview
-
File System Types
-
Customization
-
File Uploader
-
-
Popup and Notifications
-
Navigation
- Overview
- Accordion
-
Action Sheet
-
Context Menu
-
Menu
- Multi View
-
Drawer
-
Tab Panel
-
Tabs
-
Toolbar
-
Stepper
- Pagination
-
List
-
Tree View
- Right-to-Left Support
-
Layout
-
Tile View
- Splitter
-
Gallery
- Scroll View
- Box
- Responsive Box
-
-
Interactive Wrappers
-
Sortable
- Resizable
-
-
Progress Indicators
-
Maps
- Overview
-
Map
-
Vector Map
-
Data Binding
- Multiple Layers
-
Markers
- Legend
-
Zooming and Panning
-
Customization
-
-
Localization
Related Demos:
Your search did not match any results.
Vue Charts - Export Custom Markup
The DevExpress.viz.exportFromMarkup(markup, options) method allows you to export SVG content, including SVG-based DevExtreme components, to an image or document.
The markup parameter accepts valid SVG markup (see the prepareMarkup() function in the code). To get the markup of a component, call its svg() method. The options parameter accepts an object whose fields configure export properties. In this demo, we specify the width, height, format, and svgToCanvas fields. Refer to the method description for more information on these and other available fields.
Backend API
<template>
<div id="chart-demo">
<div class="chart-environment">
<Form ref="form"/>
<DxChart
id="chart"
ref="chart"
:data-source="dataSource"
palette="Violet"
>
<DxCommonSeriesSettings
:bar-padding="0.3"
argument-field="state"
type="bar"
/>
<DxSeries
value-field="year2000"
name="2000"
/>
<DxSeries
value-field="year2010"
name="2010"
/>
<DxSeries
value-field="year2020"
name="2020"
/>
<DxSeries
value-field="year2021"
name="2021"
/>
<DxSeries
value-field="year2022"
name="2022"
/>
<DxLegend
vertical-alignment="bottom"
horizontal-alignment="center"
/>
<DxTitle
text="Oil Production"
subtitle="(in millions tonnes)"
/>
</DxChart>
</div>
<div class="controls-pane">
<DxButton
id="export"
:width="145"
icon="export"
type="default"
text="Export"
@click="onClick()"
/>
</div>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import {
DxChart,
DxSeries,
DxCommonSeriesSettings,
DxLegend,
DxTitle,
} from 'devextreme-vue/chart';
import { exportFromMarkup } from 'devextreme/viz/export';
import DxButton from 'devextreme-vue/button';
import { Canvg } from 'canvg';
import { dataSource } from './data.ts';
import Form from './Form.vue';
const form = ref();
const chart = ref();
const prepareMarkup = (chartSVG: string, sourceContainer: HTMLElement): SVGElement => {
const sourceElements = sourceContainer.querySelectorAll('*');
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
svg.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
svg.setAttribute('version', '1.1');
svg.setAttribute('width', '820px');
svg.setAttribute('height', '420px');
const clonedContainer = sourceContainer.cloneNode(true) as HTMLElement;
const clonedElements = clonedContainer.querySelectorAll('*');
clonedElements.forEach((clonedEl, index) => {
const sourceEl = sourceElements[index] as HTMLElement;
if (!sourceEl) return;
const computed = window.getComputedStyle(sourceEl);
['fill', 'font-family', 'font-size', 'font-weight', 'opacity', 'stroke', 'stroke-width'].forEach((prop) => {
const value = computed.getPropertyValue(prop)?.trim();
if (value && value !== 'auto' && value !== 'normal' && value !== 'initial') {
(clonedEl as SVGElement).setAttribute(prop, value);
}
});
});
svg.innerHTML = clonedContainer.innerHTML;
const group = document.createElementNS('http://www.w3.org/2000/svg', 'g');
group.setAttribute('transform', 'translate(305,12)');
group.innerHTML = chartSVG;
svg.appendChild(group);
return svg;
};
function onClick(): void {
const chartSVG = chart.value.instance.svg();
const formContent = form.value.getMarkup();
exportFromMarkup(prepareMarkup(chartSVG, formContent), {
width: 820,
height: 420,
margin: 0,
format: 'png',
svgToCanvas(svg: SVGElement, canvas: HTMLCanvasElement) {
return new Promise((resolve) => {
const v = Canvg.fromString(
canvas.getContext('2d')!,
new XMLSerializer().serializeToString(svg),
);
resolve(v.render());
});
},
});
}
</script>
<style>
#chart-demo {
height: 460px;
}
#chart {
position: absolute;
top: 12px;
right: 35px;
width: 480px;
height: 347px;
}
.chart-environment {
width: 820px;
position: relative;
margin: 0 auto;
}
.controls-pane {
display: block;
text-align: center;
}
</style>
<template>
<div class="custom-markup-container">
<svg
version="1.1"
width="820px"
height="420px"
>
<path
d="M 0 0 L 820 0 L 820 420 L 0 420 L 0 0"
stroke="#999999"
stroke-width="1"
stroke-linecap="butt"
fill="white"
stroke-linejoin="miter"
/>
<path
d="M 13 407 L 128 407 L 232 39 L 13 39"
fill="#6D39C3"
/>
<path
d="M 46 381 L 161 381 L 265 13 L 46 13"
opacity="0.5"
fill="#6D39C3"
/>
<text
transform="translate(30,89)"
class="custom-markup-text custom-markup-text-title"
>
<tspan
x="0"
y="0"
>Export </tspan>
<tspan
x="0"
y="38"
>Custom</tspan>
<tspan
x="0"
y="76"
>Markup</tspan>
</text>
<text
transform="translate(32,199)"
class="custom-markup-text custom-markup-text-subtitle"
>
<tspan
x="0"
y="0"
>Export a chart with</tspan>
<tspan
x="0"
y="19.2"
>custom elements</tspan>
</text>
</svg>
</div>
</template>
<script setup lang="ts">
defineExpose({
getMarkup(): HTMLElement {
// @ts-ignore
return this.$el;
},
});
</script>
<style>
.custom-markup-text {
fill: #fff;
font-family: 'Segoe UI', 'Helvetica Neue', 'Trebuchet MS', Verdana, sans-serif;
}
.custom-markup-text-title {
font-size: 36px;
font-weight: bold;
}
.custom-markup-text-subtitle {
font-size: 14px;
opacity: 0.8;
}
</style>
export const dataSource = [{
state: 'Saudi Arabia',
year2000: 408,
year2010: 407,
year2020: 498,
year2021: 515,
year2022: 602,
}, {
state: 'USA',
year2000: 288,
year2010: 270,
year2020: 713,
year2021: 711,
year2022: 762,
}, {
state: 'Mexico',
year2000: 150,
year2010: 146,
year2020: 101,
year2021: 97,
year2022: 95,
}];
import { createApp } from 'vue';
import App from './App.vue';
createApp(App).mount('#app');
<!DOCTYPE html>
<html lang="en">
<head>
<title>DevExtreme Demo</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0" />
<link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/26.1.5/css/dx.light.css" />
<link rel="stylesheet" type="text/css" href="./bundle.css" />
</head>
<body class="dx-viewport">
<div class="demo-container">
<div id="app"> </div>
</div>
<script src="bundles/vendor/vue.vendor.js"></script>
<script src="./bundle.js"></script>
</body>
</html>