The ColumnChart we generated normally contains both the bound value column name and the Series name on the X axis. For the same data, only the Series name is displayed on the X axis of the chart generated in the Excel chart, and does not contain the name of the bound value column. In this case, you can easily control the effect of the latter by using the following code:
This. UltraChart1.Axis. X. Labels. Visible = false;
This. UltraChart1.Axis. X. Labels. SeriesLabels. Visible = true;
By setting attributes, you can easily set the Label display style. If you want to customize the labels of ColumnChart or other charts to display specific information, how can we achieve this goal without simple attribute settings? In general, we need to implement the IRenderLabel interface to customize the Label display format, and then set the Label display format of the X axis as our defined style.
The IRenderLabel interface has only one ToString (Hashtable context) member ). Contest contains information about the tags to be processed. For example, context ["ITEM_LABEL"] indicates the column name, and context ["DATA_VALUE"] indicates the specific value of a specific column. The return value of ToString (Hashtable context) will be written to the tag. For example, if the return value is always "Hello world", "Hello world" will be displayed on the X axis again. The following code implements the IRenderLabel interface.
Using Infragistics. UltraChart. Resources;
...
Public class MyLabelRenderer: IRenderLabel
{
Public string ToString (Hashtable context)
{
Double dataValue = (double) context ["DATA_VALUE"];
If (dataValue> 75)
Return dataValue. ToString () + "[Very High]";
Else if (dataValue> 50)
Return dataValue. ToString () + "[High]";
Else if (dataValue> 25)
Return dataValue. ToString () + "[Medium]";
Else if (dataValue> = 0)
Return dataValue. ToString () + "[Low]";
Else
Return dataValue. ToString () + "[Negative]";
}
}
All we need to do is set the ItemFormatString of the chart axis to a specific character, which cannot conflict with the existing name of the chart, and this character must be included between the "<" and ">" characters. Then, create a Hashtable instance with the same key name as the ItemFormatString of the configured chart axis, the key value is a class instance that implements the IRenderLabel interface. Finally, we need to set the LabelHash attribute of the chart to the Hashtable instance. The specific implementation code is as follows:
This. ultraChart1.Axis. Y. Labels. ItemFormatString = "<MY_VALUE> ";
This. ultraChart1.Axis. X. Labels. ItemFormatString = "<MY_VALUE> ";
Hashtable MyLabelHashTable = new Hashtable ();
MyLabelHashTable. Add ("MY_VALUE", new MyLabelRenderer ());
This. ultraChart1.LabelHash = MyLabelHashTable;
This. ultraChart1.DataSource = GetColumnData ();
For the final graphic effect, see Figure 1:
Figure 1 custom axis label Effect