I would like to show data values on a 2D column chart (see attachment). Currently, I can do this on a 3D pie chart very easily, but I can't figure out how to make it happen on a 2D column chart. I can't use a 3D chart because there are times when a bank account might be overdrawn and have a negative value.
Hi,
To get the data values to display on the chart use the ChartText collection.
http://help.infragistics.com/doc/WinForms/2016.1/CLR4.0/?page=Chart_Apply_Chart_Text_Labels.html has a walkthrough applying chart text and modifying the alignment of the text. The basic code would go something like this:
Infragistics.UltraChart.Resources.Appearance.ColumnChartAppearance columnChartapp = new Infragistics.UltraChart.Resources.Appearance.ColumnChartAppearance();
Infragistics.UltraChart.Resources.Appearance.ChartTextAppearance chartTextApp = new Infragistics.UltraChart.Resources.Appearance.ChartTextAppearance();
chartTextApp.ChartTextFont = new System.Drawing.Font("Arial", 7F);
chartTextApp.ClipText = false;
chartTextApp.Column = -2;
chartTextApp.ItemFormatString = "<DATA_VALUE:00.00>";
chartTextApp.Row = -2;
chartTextApp.Visible = true;
columnChartapp.ChartText.Add(chartTextApp);
this.ultraChart1.ColumnChart = columnChartapp;
I got something working, but the text sits right over the top line of the column. Is there a way to move it up a little bit?
chartTextApp.VerticalAlign = StringAlignment.Far;
will move that above the column.
Keep in mind the text won't flow outside the chart area bounds so your checking data value text may still get pushed down, you would have to add some extra space to the top by customizing the range on the y-axis.
Can you point me in the right direction on how to do this for a 3D column chart?
If you want to keep it simple you can replace the chartText.ItemFormatString from chartTextApp.ItemFormatString = "<DATA_VALUE:00.00>"; to chartTextApp.ItemFormatString = "<DATA_VALUE:#>"; but you'll lose some formatting. Otherwise you'll have to use IRenderLabel and do something like this:
Change ItemFormatString to something not reserved:
chartTextApp.ItemFormatString = "<MY_CUSTOM_LABEL>";
Create the IRenderLabel implementation:
public class MyLabelRenderer : Infragistics.UltraChart.Resources.IRenderLabel
{
public string ToString(Hashtable context)
double dataVal = (double)context["DATA_VALUE"];
if (dataVal <= 10.0)
return string.Empty;
}
return dataVal.ToString("0.00");
hook up the LabelHash like this:
Hashtable MyHashtable = new Hashtable();
MyHashtable.Add("MY_CUSTOM_LABEL", new MyLabelRenderer());
this.ultraChart1.LabelHash = MyHashtable;
Is there any way to conditionally display chart text? I don't want to show the text if the value is zero.
ChartText only applies to 2D chart appearance objects and is not supported on 3D ChartAppearance objects.