0

I am trying to customize the series labels of the X axis of a linear ultrachart using vb.net.

I looked into the documentation from Infragistics and found that I could use this code:

UltraChart.Axis.Y.Labels.SeriesLabels.FormatString = "<Item_Label>"

A description of the types of labels available can be seen here. However, I'm not getting the result I expected. I get "Row#1" and I want to get only the "1".

I've tried the approach used in the first reply of this post in Infragistics forums, which consists of using an hashtable with the customized labels. The code used there is the following (in C#):

Hashtable labelHash = new Hashtable();
labelHash.Add("CUSTOM", new MyLabelRenderer());
ultraChart1.LabelHash = labelHash;
xAxis.Labels.ItemFormatString = "<CUSTOM>";

public class MyLabelRenderer : IRenderLabel
{
    public string ToString(Hashtable context)
    {
        string label = (string)context["ITEM_LABEL"];
        int row = (int)context["DATA_ROW"];
        int col = (int)context["DATA_COLUMN"];
        //use row, col, current label's text or other info inside the context to get the axis label.
        //the string returned here will replace the current label.
        return label;
    }
}

This approach didn't work either. I am using Infragistics NetAdvantage 2011.1.

Anyone has any idea how to customize these labels in order to obtain the number after "Row#"?

4

2 回答 2

0

有不同的方法来解决这个任务。如果您使用 FillSceneGraph 事件,一种可能的解决方案可能是。通过这种方式,您可以获得 TEXT 原语并对其进行修改。例如:

 private void ultraChart1_FillSceneGraph(object sender, Infragistics.UltraChart.Shared.Events.FillSceneGraphEventArgs e)
    {
        foreach (Primitive pr in e.SceneGraph)
        {
            if (pr is Text  &&((Text)pr).labelStyle.Orientation == TextOrientation.VerticalLeftFacing )
            {
                pr.PE.Fill = Color.Red;
                ((Text)pr).SetTextString("My custom labels");
            }
        }
    }
于 2013-08-13T07:12:16.220 回答
0

好的。我将尝试更深入地解释 FormatString 属性。当您使用此属性时,您可以确定要显示哪些信息(例如:项目值或数据值或系列值)。当然,也可以选择使用您的自定义 FormatString。例如:

axisX2.Labels.ItemFormat=AxisItemLabelFormat.Custom; axisX2.Labels.ItemFormatString ="";

在这种情况下,我们有代表 X 轴上日期的标签,因此如果您使用这两个属性,您可以确定日期格式(例如 dd/MM/yyyy 或 MM/ddd/yy)。在您的场景中,您的 X 轴上有字符串值。如果您无法在较低级别修改这些字符串值(例如在您的数据库中,通过 TableAdapters SQL 查询、DataSet,即在将您的 DataSource 设置为我们的 UltraChart 之前),那么您可以使用 FillSceneGraph 事件并修改您的 Text 基元。有关此事件的更多详细信息,请访问http://help.infragistics.com/Help/NetAdvantage/WinForms/2013.1/CLR4.0/html/Chart_Modify_Scene_Graph_Using_FillSceneGraph_Event.html 如果您需要样品或其他帮助,请随时在我们的网站上创建一个新的论坛主题 -http://www.infragistics.com/community/forums/
我很乐意为您提供帮助。

于 2013-08-14T06:20:22.503 回答