Export Custom Legend with Chart Export

1 Answer 23 Views
Chart (HTML5) ClientExportManager
Jerry
Top achievements
Rank 2
Iron
Iron
Jerry asked on 16 Feb 2022, 04:03 PM

I had to use a custom chart legend but can't seem to figure out how to export the custom legend when exporting to pdf.

html:
<telerik:RadButton RenderMode="Lightweight" runat="server" OnClientClicked="exportChart1" Text="Export to PDF" AutoPostBack="false" UseSubmitBehavior="false"></telerik:RadButton>

Javascript:
function exportChart1() {
var $ = $telerik.$;
var ddlValue = $find("<%= ddlChart1.ClientID %>").get_selectedItem().get_value();
var selectedChart = "." + ddlValue;

/*The selectedChart is found by the CssClass of the chart*/
$find('<%=RadClientExportManager1.ClientID%>').exportPDF($(selectedChart));
}

The custom legend :

<div class="customLegendWrapper">
<div class="customLegend">
<div class="series1">
<div></div>
Series 1
</div>
<div class="series2">
<div></div>
Series 2
</div>
<div class="series3">
<div></div>
Series 3
</div>
</div>
</div>

1 Answer, 1 is accepted

Sort by
0
Vessy
Telerik team
answered on 18 Feb 2022, 04:09 PM

Hi Jerry,

The easiest way to export two elements from a web page (the chart and the legend) is to wrap them inside a common wrapper and pass its class/id to the ClientExportManager.

For example:

        <telerik:RadClientExportManager ID="RadClientExportManager1" runat="server"></telerik:RadClientExportManager>
        <telerik:RadComboBox ID="ddlChart1" runat="server">
            <Items>
                <telerik:RadComboBoxItem Text="chart1" Value="firstChartWrapper" />
                <telerik:RadComboBoxItem Text="chart2" Value="secondChartWrapper" />
            </Items>
        </telerik:RadComboBox>
        <telerik:RadButton ID="RadButton1" runat="server" AutoPostBack="false" Text="Export" OnClientClicked="exportChart1"></telerik:RadButton>


        <div class="firstChartWrapper">
            <telerik:RadHtmlChart runat="server" ID="RadHtmlChart2" Height="300px" Width="100%" CssClass="chart1">
                ...
            </telerik:RadHtmlChart>
            <div class="customLegendWrapper">
                <div class="customLegend">
                    <div class="series1">
                        <div></div>
                        Series 1
                    </div>
                    <div class="series2">
                        <div></div>
                        Series 2
                    </div>
                    <div class="series3">
                        <div></div>
                        Series 3
                    </div>
                </div>
            </div>
        </div>

        <script>
            var $ = $telerik.$;
            function exportChart1() {

                var ddlValue = $find("<%= ddlChart1.ClientID %>").get_selectedItem().get_value();
                        var selectedChart = "." + ddlValue;
                            /*The selectedChart is found by the CssClass of the chart*/
                            $find('<%=RadClientExportManager1.ClientID%>').exportPDF($(selectedChart));
            }
        </script>

Regards,
Vessy
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Chart (HTML5) ClientExportManager
Asked by
Jerry
Top achievements
Rank 2
Iron
Iron
Answers by
Vessy
Telerik team
Share this question
or