The following example demonstrates how to export a chart to HTML and MHT files.
To export the chart, use the appropriate ExportTo~ method (e.g., ChartControlBase.ExportToHtml, ChartControlBase.ExportToPdf, ChartControlBase.ExportToMht etc.).
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts" x:Class="Export.MainWindow"
Title="MainWindow" Height="350" Width="525">
<Grid>
<dxc:ChartControl x:Name="chartControl" >
<dxc:ChartControl.Legend>
<dxc:Legend/>
</dxc:ChartControl.Legend>
<dxc:XYDiagram2D>
<dxc:BarSideBySideSeries2D DisplayName="Series 1">
<dxc:SeriesPoint Argument="A" Value="2"/>
<dxc:SeriesPoint Argument="B" Value="13"/>
<dxc:SeriesPoint Argument="C" Value="15"/>
<dxc:SeriesPoint Argument="D" Value="17"/>
</dxc:BarSideBySideSeries2D>
</dxc:XYDiagram2D>
</dxc:ChartControl>
<StackPanel Orientation="Horizontal">
<Button Content="Export To HTML" VerticalAlignment="Top" Width="95" Click="Button_Click"/>
<Button Content="Export To MHT" VerticalAlignment="Top" Width="95" Click="Button_Click_1"/>
</StackPanel>
</Grid>
</Window>
using System.Diagnostics;
using System.IO;
using System.Windows;
using DevExpress.Xpf.Charts;
using DevExpress.XtraPrinting;
namespace Export {
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
}
private void ExportChartToHTML(ChartControl chart) {
// Create an object containing HTML export options.
HtmlExportOptions htmlOptions = new HtmlExportOptions();
// Set HTML-specific export options.
htmlOptions.CharacterSet = "utf-8";
htmlOptions.RemoveSecondarySymbols = false;
htmlOptions.Title = "Unicode UTF-8 Example";
// Specify print size mode.
PrintSizeMode sizeMode = PrintSizeMode.Stretch;
// Export a chart to an HTML file.
chart.ExportToHtml("OutputUnicode.html", htmlOptions, sizeMode);
Process.Start("OutputUnicode.html");
}
private void ExportChartToMHT(ChartControl chart) {
// Create an object containing MHT export options.
MhtExportOptions mhtOptions = new MhtExportOptions();
// Specify print size mode.
PrintSizeMode sizeMode = PrintSizeMode.ProportionalZoom;
// Export a chart to a stream as MHT.
FileStream mhtStream = new FileStream("OutputDefault.mht", FileMode.Create);
chart.ExportToMht(mhtStream, mhtOptions, sizeMode);
Process.Start("OutputDefault.mht");
}
private void Button_Click(object sender, RoutedEventArgs e) {
ExportChartToHTML(chartControl);
}
private void Button_Click_1(object sender, RoutedEventArgs e) {
ExportChartToMHT(chartControl);
}
}
}
Imports Microsoft.VisualBasic
Imports System.Diagnostics
Imports System.IO
Imports System.Windows
Imports DevExpress.Xpf.Charts
Imports DevExpress.XtraPrinting
Namespace Export
Partial Public Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub ExportChartToHTML(ByVal chart As ChartControl)
' Create an object containing HTML export options.
Dim htmlOptions As New HtmlExportOptions()
' Set HTML-specific export options.
htmlOptions.CharacterSet = "utf-8"
htmlOptions.RemoveSecondarySymbols = False
htmlOptions.Title = "Unicode UTF-8 Example"
' Specify print size mode.
Dim sizeMode As PrintSizeMode = PrintSizeMode.Stretch
' Export a chart to an HTML file.
chart.ExportToHtml("OutputUnicode.html", htmlOptions, sizeMode)
Process.Start("OutputUnicode.html")
End Sub
Private Sub ExportChartToMHT(ByVal chart As ChartControl)
' Create an object containing MHT export options.
Dim mhtOptions As New MhtExportOptions()
' Specify print size mode.
Dim sizeMode As PrintSizeMode = PrintSizeMode.ProportionalZoom
' Export a chart to a stream as MHT.
Dim mhtStream As New FileStream("OutputDefault.mht", FileMode.Create)
chart.ExportToMht(mhtStream, mhtOptions, sizeMode)
Process.Start("OutputDefault.mht")
End Sub
Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
ExportChartToHTML(chartControl)
End Sub
Private Sub Button_Click_1(ByVal sender As Object, ByVal e As RoutedEventArgs)
ExportChartToMHT(chartControl)
End Sub
End Class
End Namespace