下面的示例演示了如何把图表导出为 HTML 和 MHT 文件。 可以在应用程序中使用类似的方法,把 ChartControl 导出为 HTML 或 MHT。

C#CopyCode image复制代码
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.
        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.
        FileStream mhtStream = new FileStream("OutputDefault.mht", FileMode.Create);
        chart.ExportToMht(mhtStream, mhtOptions);
    }
}
Visual BasicCopyCode image复制代码
Imports System.IO
Imports DevExpress.XtraCharts
Imports DevExpress.XtraPrinting
' ...

Private Sub ExportChartToHTML(ByRef Chart As ChartControl)
    If (Chart.IsPrintingAvailable) Then
        ' 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"

        ' Export a chart to an HTML file.
        Chart.ExportToHtml("OutputUnicode.html", HtmlOptions)

        ' Export a chart to a stream as HTML.
        Dim HtmlStream As New FileStream("OutputDefault.html", FileMode.Create)
        Chart.ExportToHtml(HtmlStream, HtmlOptions)
    End If
End Sub

Private Sub ExportChartToMHT(ByRef Chart As ChartControl)
    If (Chart.IsPrintingAvailable) Then
        ' Create an object containing MHT export options.
        Dim MhtOptions As 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.
        Dim MhtStream As New FileStream("OutputDefault.mht", FileMode.Create)
        Chart.ExportToMht(MhtStream, MhtOptions)
    End If
End Sub