Hi
I'm hoping to get help with something that is probably easy to achieve ...
I would like to replicate an Excel style 100% Stacked Bar chart as per the attached example but just can't figure out what to do.
I've experimented with a 2D StackedBarChart but with the tabular data being used I get a separate row on the y axis for each range. Effectively I want a single row on the y axis consisting of the different range values in series.
Ideally I'd also like to use specific colours for range values so that '0 - 39 (Critical)' is red, '95 - 100 (Very Good)' is green and so on. Perhaps that should be a separate quesion to be asked after I get the basic chart layout working.
Any tips to point me in the right direction would be very much appreciated.
Adrian
Try using SwapRowsAndColumns property to get a single stack of values. For the brushes, you can set up a color array and use it as a color model.DataTable dt = new DataTable();dt.Columns.Add("label", typeof(string));dt.Columns.Add("Condition Scores", typeof(int));dt.Rows.Add("0 - 39 (Critical)", 60);dt.Rows.Add("40 - 64 (Very Poor)", 80);dt.Rows.Add("65 - 79 (Poor)", 130);dt.Rows.Add("80 - 89 (Fair)", 300);dt.Rows.Add("90 - 94 (Good)", 290);dt.Rows.Add("95 - 100 (Very Good)", 140);
ultraChart1.ChartType = ChartType.StackBarChart;ultraChart1.Data.DataSource = dt;ultraChart1.Data.SwapRowsAndColumns = true;
ultraChart1.ColorModel.CustomPalette = new Color[] { Color.Blue, Color.Red, Color.Yellow, Color.Turquoise, Color.Magenta, Color.Salmon };
ultraChart1.ColorModel.ModelStyle = ColorModels.CustomLinear;
Great stuff, thanks very much Max.
One other question. Data values displayed on the chart and in tooltips are cumulative and not the raw value for a specific row, i.e. 60 is shown for Critical, 140 is shown for Very Poor, 270 for Poor and so on.
Is there an easy way to display the actual values (60, 80, 130 ...) instead?
Many thanks
Hello ,
I had been following Max’s suggestion in order to create a sample. Please run the sample and let me know if this is what you are looking for.
Please let me know if you have any further questions.
That has sorted it out for me, thanks very much Hristo.
I have modify the sample base on your code snipped and your requirements. Pease run the sample and let me know if this is what you are looking for.
Hi Hristo
Apologies for not having replied to your previous post.
I'm very nearly there now but have one small issue left to resolve. I have a class 'StackChartValueRender' implementing the 'IRenderLabel' interface which I'm hooking up to in the chart load event handler (see code snippets below).
When the chart is first displayed, just the DATA_VALUE_ITEM values are shown but if I move the mouse over the chart then suddenly the desired format with percentage is shown. It's as if the custom format only comes into play on some sort of refresh.
Thanks again for your help.
In the chart load event handler:
Hashtable stackChartValueHashTable = new Hashtable(); stackChartValueHashTable.Add("PC_VALUE", new StackChartValueRenderer()); ucCiGeneral.LabelHash = stackChartValueHashTable; ucCiGeneral.Axis.X.Labels.ItemFormat = AxisItemLabelFormat.Custom; ucCiGeneral.Axis.Y.Labels.ItemFormat = AxisItemLabelFormat.Custom; ucCiGeneral.Axis.X.Labels.ItemFormatString = "<PC_VALUE>"; ucCiGeneral.Axis.Y.Labels.ItemFormatString = "<PC_VALUE>";
IRenderLabel class:
public class StackChartValueRenderer : Infragistics.UltraChart.Resources.IRenderLabel { public string ToString(Hashtable context) { if (context["DATA_ROW"] != null) { double dataValueItem = (double)context["DATA_VALUE_ITEM"]; double totalValue = (double)context["DATA_VALUE_ACCUMULATED_ELEMENT"]; double percentage = (((dataValueItem > 0) && (totalValue > 0)) ? dataValueItem / totalValue : 0); return (String.Format("{0}{1}({2:0.0%})", dataValueItem, Environment.NewLine, percentage)); } return ((double)context["DATA_VALUE_ITEM"]).ToString(); } }
Hi,
I just wanted to know if you were able to solve your issue based on my suggestions or you still need help? Just let me know.
Thank you.
You could achieve your goal if you use IRenderLabel Interface. On the following link you will find a tutorial how to “Customize Labels Using the IRenderLabel Interface”:
http://help.infragistics.com/Help/NetAdvantage/WinForms/2010.2/CLR2.0/html/Chart_Customize_Labels_Using_the_IRenderLabel_Interface.html
please let me know if you have any further questions.