We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Changing/customizing the text displayed in labels/legends?

We're using the OLAP Chart control for ASP.NET MVC5 in a financial analysis application. I would like to know if there's a way to change how the text for labels and legends is generated.

For example, we'd like to be able to display a chart of all sales data for a particular vendor. We might add that constraint in the report builder like this:
DimensionElement newDimension = new DimensionElement();
newDimension.Name = "Vendors";
newDimension.AddLevel("ID", "ID");
newDimension.Hierarchy.LevelElements["ID"].Add("1");
newDimension.Hierarchy.LevelElements["ID"].IncludeAvailableMembers = true;
olapReport.CategoricalElements.Add(newDimension);
However, since the key we are using to fetch the vendor is an ID number, the label and legend text will display something along the lines of: "1~ProductA, 1~ProductB, etc..." With more dimensions, this becomes even more unintelligible.

Is it possible to change how the label/legend text is generated from within the OLAP chart service? Can we change an element's display title without affecting its value? Or is there a setting to prevent particular elements from being included in this text?

Thanks,
Matt, CodeASite

3 Replies

NM Narendhran M Syncfusion Team March 30, 2015 06:30 AM UTC

Hi Matthew,

Thanks for using Syncfusion Products.

For customizing the Legend labels, kindly use the event “LegendItemRendering”, in which the names of all the legends could be customized individually. Similarly for customizing the Axis labels, the event “AxesLabelRendering” lets to rename the legends as per our requirement.

Please find the code snippet below for achieving both the scenarios mentioned above.

Code Snippet (~.cshtml)

<script>

function OnAxisLabelRendering(args) {

if (args.data.label.Text == "YourLabel")

args.data.label.Text = "CustomLabelText";

}

function OnLegendItemRendering(args) {

if (args.data.legendItem.Text == "YourLegend")

args.data.legendItem.Text = "CustomLegendText";

}

</script>

<div>

@Html.EJ().Olap().OlapChart("OlapChart1").Url(Url.Content("~/wcf/OlapChartService.svc")).ClientSideEvents( oEve => { oEve.AxesLabelRendering("OnAxisLabelRendering").LegendItemRendering("OnLegendItemRendering"); })

</div>

Please let us know if you require any further assistance.

Regards,

Narendhran M.



MF Matthew Fekete March 31, 2015 06:49 PM UTC

So, just to be clear, there is no way to alter the text displayed in a legend or label before it is rendered? i.e. the only way to change the text is to identify the generated string client-side?

Regards,
Matt


NM Narendhran M Syncfusion Team April 1, 2015 03:39 PM UTC

Hi Matthew,
As per the architecture, the rendering of our OlapChart control is completely carried out in the script side. Hence the best way to customize the legend and axis labels would be the usage of the events mentioned in the previous update.

Please let us know if you have any concern.
Regards,
Narendhran M.

Loader.
Live Chat Icon For mobile
Up arrow icon