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

Translating RadHTMLChart (bar chart)

2 Answers 59 Views
Chart (HTML5)
This is a migrated thread and some comments may be shown as answers.
Kerry
Top achievements
Rank 1
Kerry asked on 23 Jun 2014, 08:25 PM
The goal is to take an already finished rad bar chart and change the labels along the x axis to French.  My first thought was to try this:

  private void ProcessXAxis(ChartXAxis xAxis)
        {
            if (xAxis == null || xAxis.Items == null) return;

            foreach (AxisItem item in xAxis.Items)
            {
                var replacementPhrase = GetFilteredReplacementPhrase(item.LabelText);
                if (string.IsNullOrEmpty(replacementPhrase) || string.IsNullOrWhiteSpace(replacementPhrase)) continue;
                item.LabelText = replacementPhrase;
            }
        }

Trouble is, for this particular chart, there are no items in the collection.  Where the chart gets its labels, other than obviously from the data row column names, is beyond me.  Apparently I don't understand the ChartXAxis Item collection enough and assumed incorrectly it represented each data row. It doesn't.

So, this leaves me with the question - how do I find the correct class containing the textblock that is obviously being generated in HTML as a "Text" element under the <g> element?  Please understand that all I have to work with at the point I am doing this processing is an already created chart.  I have no access to the data source and can only use the class trees available from Telerik.

KT

2 Answers, 1 is accepted

Sort by
0
Danail Vasilev
Telerik team
answered on 26 Jun 2014, 11:59 AM
Hi KT,

Could you please elaborate more about the control type you are using? Is this the RadHtmlChart or the obsolete RadChart control?

If you mean RadHtmlChart, note that the control renders entirely on the client and therefore its series/category items are not available on the server (see Known Limitations help article). You can, however, modify them on the client as follows:
ASPX:
<telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
<script>
    function OnClientClicked(sender, args) {
        var chart = $find("<%=ColumnChart1.ClientID%>");
        chart._chartObject.options.categoryAxis.categories[1] = "new Item Label";
        chart.repaint();
    }
</script>
<telerik:RadButton ID="RadButton1" runat="server" Text="Change XAxis Labels" AutoPostBack="false" OnClientClicked="OnClientClicked" />
<telerik:RadHtmlChart runat="server" ID="ColumnChart1" Width="600px" Height="400px">
    <PlotArea>
        <Series>
            <telerik:ColumnSeries Name="Product 1">
                <SeriesItems>
                    <telerik:CategorySeriesItem Y="15000" />
                    <telerik:CategorySeriesItem Y="23000" />
                    <telerik:CategorySeriesItem Y="10000" />
                </SeriesItems>
            </telerik:ColumnSeries>
        </Series>
        <XAxis>
            <Items>
                <telerik:AxisItem LabelText="Item 1" />
                <telerik:AxisItem LabelText="Item 2" />
                <telerik:AxisItem LabelText="Item 3" />
            </Items>
        </XAxis>
    </PlotArea>
</telerik:RadHtmlChart>


Regards,
Danail Vasilev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Kerry
Top achievements
Rank 1
answered on 27 Jun 2014, 01:02 PM
Thanks for your time and answer.  It is the RadHTMLChart, and I suspected much of this is not obtainable server-side.

Kerry
Tags
Chart (HTML5)
Asked by
Kerry
Top achievements
Rank 1
Answers by
Danail Vasilev
Telerik team
Kerry
Top achievements
Rank 1
Share this question
or