I am facing the same problem that was Addressed in Question Q362164. I have handled ChartControl.CustomDrawSeries in a ViewController to set the LegendText parameter according to the processed series. but i am facing problem in it. I have created a sample project and also attached a image to demonstrate the desire View. I have also pointed the area in a code where i am facing problem. Please help to perform this
We have closed this ticket because another page addresses its subject:
Localization - How to use localized enumeration values from the Application Model with data bound controlsProblem in displaying Enum List in Chart ( Enum List is not Displayed as required)
Answers approved by DevExpress Support
Hello,
I have corrected your sample project:
C#using System;
using System.Text;
using DevExpress.XtraCharts;
using DevExpress.ExpressApp;
using System.Collections.Generic;
using DevExpress.ExpressApp.Utils;
using DevExpress.ExpressApp.Chart.Web;
using DevExpressSamplePorblem.Module.DomainComponents;
namespace DevExpressSamplePorblem.Module.Web.Controllers
{
public partial class ChartController : ViewController {
EnumDescriptor opportunitySourceEnumDescriptor;
ASPxChartListEditor chartListEditor;
public ChartController() {
InitializeComponent();
RegisterActions(components);
//TargetViewId = "ILead_ListView_Chart";
TargetViewId = "ICRMOpportunity_ChartView";
}
protected override void OnViewControlsCreated() {
base.OnViewControlsCreated();
chartListEditor = ((ListView)View).Editor as ASPxChartListEditor;
if(chartListEditor != null) {
opportunitySourceEnumDescriptor = new EnumDescriptor(typeof(OpportunitySource));
chartListEditor.ChartControl.CustomDrawSeries += new CustomDrawSeriesEventHandler(ChartControl_CustomDrawSeries);
//chartListEditor.ChartControl.CustomDrawSeriesPoint += new CustomDrawSeriesPointEventHandler(ChartControl_CustomDrawSeriesPoint);
chartListEditor.ChartControl.CustomDrawAxisLabel += new CustomDrawAxisLabelEventHandler(ChartControl_CustomDrawAxisLabel);
}
}
protected override void OnDeactivated() {
if(chartListEditor != null && chartListEditor.ChartControl != null) {
chartListEditor.ChartControl.CustomDrawSeries -= new CustomDrawSeriesEventHandler(ChartControl_CustomDrawSeries);
//chartListEditor.ChartControl.CustomDrawSeriesPoint -= new CustomDrawSeriesPointEventHandler(ChartControl_CustomDrawSeriesPoint);
chartListEditor.ChartControl.CustomDrawAxisLabel -= new CustomDrawAxisLabelEventHandler(ChartControl_CustomDrawAxisLabel);
}
base.OnDeactivated();
}
void ChartControl_CustomDrawAxisLabel(object sender, CustomDrawAxisLabelEventArgs e) {
string caption = opportunitySourceEnumDescriptor.GetCaption(Convert.ToInt32(e.Item.AxisValueInternal));
e.Item.Text = caption;
}
//void ChartControl_CustomDrawSeriesPoint(object sender, CustomDrawSeriesPointEventArgs e) {
//}
void ChartControl_CustomDrawSeries(object sender, CustomDrawSeriesEventArgs e) {
StringBuilder sb = new StringBuilder(opportunitySourceEnumDescriptor.Values.Length);
for(int i = 0; i < opportunitySourceEnumDescriptor.Values.Length; i++) {
sb.AppendLine(opportunitySourceEnumDescriptor.GetCaption(i));
}
e.LegendText = sb.ToString();
}
}
}
If you are using a pie chart, you can handle the WebChartControl > CustomDrawSeriesPoint event:
C#using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ChartView.Module.BusinessObjects;
using DevExpress.Data.Filtering;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Chart.Web;
using DevExpress.ExpressApp.Editors;
using DevExpress.ExpressApp.Layout;
using DevExpress.ExpressApp.Model.NodeGenerators;
using DevExpress.ExpressApp.SystemModule;
using DevExpress.ExpressApp.Templates;
using DevExpress.ExpressApp.Utils;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.Validation;
using DevExpress.XtraCharts;
namespace ChartView.Module.Web.Controllers {
// For more typical usage scenarios, be sure to check out http://documentation.devexpress.com/#Xaf/clsDevExpressExpressAppViewControllertopic.
public partial class ChartController : ViewController<ListView> {
EnumDescriptor statusEnumDescriptor;
Type enumType = typeof(DomainObject1.Status);
ASPxChartListEditor aspxChartListEditor;
public ChartController() {
InitializeComponent();
TargetObjectType = typeof(DomainObject1);
}
protected override void OnActivated() {
base.OnActivated();
statusEnumDescriptor = new EnumDescriptor(enumType);
}
protected override void OnViewControlsCreated() {
base.OnViewControlsCreated();
// Access and customize the target View control.
aspxChartListEditor = ((ListView)View).Editor as ASPxChartListEditor;
if(aspxChartListEditor != null) {
aspxChartListEditor.ChartControl.CustomDrawSeriesPoint += ChartControl_CustomDrawSeriesPoint;
}
}
private void ChartControl_CustomDrawSeriesPoint(object sender, CustomDrawSeriesPointEventArgs e) {
string caption = statusEnumDescriptor.GetCaption(Enum.Parse(enumType, e.SeriesPoint.Argument));
e.LabelText = caption;
e.LegendText = caption;
}
protected override void OnDeactivated() {
// Unsubscribe from previously subscribed events and release other references and resources.
if(aspxChartListEditor != null && aspxChartListEditor.ChartControl != null) {
aspxChartListEditor.ChartControl.CustomDrawSeriesPoint -= ChartControl_CustomDrawSeriesPoint;
}
base.OnDeactivated();
}
}
}
I hope it will meet your needs.
P.S.
For faster replies to questions related to customizing individual controls rather than to XAF, please contact an appropriate product team (e.g., XtraCharts).