How to: Export a Chart to HTML and MHT

  • 2 minutes to read

The following example demonstrates how to export a chart to HTML and MHT files. You may use similar methods in your applications to export a ChartControl as HTML of MHT.

using System.IO;
using DevExpress.XtraCharts;
using DevExpress.XtraPrinting;
// ...

private void ExportChartToHTML(ChartControl chart) {
    if (chart.IsPrintingAvailable) {
        // 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";

        // Export a chart to an HTML file.
        chart.ExportToHtml("OutputUnicode.html", htmlOptions);

        // Export a chart to a stream as HTML.
        using (FileStream htmlStream = new FileStream("OutputDefault.html", FileMode.Create)){
            chart.ExportToHtml(htmlStream, htmlOptions);
        }
    }
}


private void ExportChartToMHT(ChartControl chart) {
    if (chart.IsPrintingAvailable) {
        // Create an object containing MHT export options.
        MhtExportOptions mhtOptions = new MhtExportOptions();

        // Set MHT-specific export options.
        mhtOptions.CharacterSet = "iso-8859-1";
        mhtOptions.Title = "Unicode UTF-8 Example";

        // Export a chart to an MHT file.
        chart.ExportToMht("OutputUnicode.mht", mhtOptions);

        // Export a chart to a stream as MHT.
        using (FileStream mhtStream = new FileStream("OutputDefault.mht", FileMode.Create)){
            chart.ExportToMht(mhtStream, mhtOptions);
        }
    }
}