This is a migrated thread and some comments may be shown as answers.

[Solved] Add RadHtmlCharts to RadGrid for Excel Export

1 Answer 152 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Torben
Top achievements
Rank 1
Torben asked on 12 Apr 2013, 01:46 PM
Hello forum,
we have three RadHtmlCharts on one page and we would like to export them to excel, all at once.
So our plan is to make a new RadGrid in code-behind, add those three charts to this grid and export that grid.
So i wrote this piece of Code:
private void ExportChartsToExcel() {
    RadGrid chartWrapperGrid = new RadGrid();
    chartWrapperGrid.ID = "ChartWrapperGrid";
    chartWrapperGrid.AutoGenerateColumns = false;
 
    GridBoundColumn boundColumn1 = new GridBoundColumn();
    boundColumn1.DataField = "Chart1";
    boundColumn1.HeaderText = "Chart 1";
    chartWrapperGrid.MasterTableView.Columns.Add(boundColumn1);
    GridBoundColumn boundColumn2 = new GridBoundColumn();
    boundColumn2.DataField = "Chart2";
    boundColumn2.HeaderText = "Chart 2";
    chartWrapperGrid.MasterTableView.Columns.Add(boundColumn2);
    GridBoundColumn boundColumn3 = new GridBoundColumn();
    boundColumn3.DataField = "Chart3";
    boundColumn3.HeaderText = "Chart 3";
    chartWrapperGrid.MasterTableView.Columns.Add(boundColumn3);
 
    DataTable chartTable = new DataTable();
    chartTable.Columns.Add("Chart1");
    chartTable.Columns.Add("Chart2");
    chartTable.Columns.Add("Chart3");
    RadHtmlChart[] chartArray = new RadHtmlChart[] { Chart1, Chart2, Chart3 };
    chartTable.Rows.Add(chartArray);
    chartWrapperGrid.DataSource = chartTable;
 
    this.form1.Controls.Add(chartWrapperGrid);
    chartWrapperGrid.ExportSettings.OpenInNewWindow = true;
    chartWrapperGrid.ExportSettings.ExportOnlyData = true;
    chartWrapperGrid.ExportSettings.IgnorePaging = true;
    chartWrapperGrid.MasterTableView.ExportToExcel();
}

The download starts as wanted but the in the grid are only the titles with "Telerik.Web.UI.RadHtmlChart" under it.
Why are the Chart not shown?


What am i doing wrong?

1 Answer, 1 is accepted

Sort by
0
Danail Vasilev
Telerik team
answered on 14 Apr 2013, 03:07 PM
Hello Torben,

Note that the RadHtmlChart is not directly available on the server, because it renders entirely on the client via JavaScript. More information about the RadHtmlChart rendering is available in its Overview help article.

Therefore I am afraid that the desired export with the RadGrid is not possible neither. What you can do, however, in order to export the RadHtmlChart is to send its SVG/VML rendering to the server and then use a third party software that will convert the SVG image to a more common user format such as PNG or PDF.

There is already created a code library on the topic called Exporting RadHtmlChart to PNG and PDF that demonstrates how to achieve this.

Kind regards,
Danail Vasilev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Torben
Top achievements
Rank 1
Answers by
Danail Vasilev
Telerik team
Share this question
or