Hello,
Is there any way to rotate Box(Whisker chart) in Infragistic Win Forms UltraChart component so it would be horizontal?
Thanks in advance
Hello Oleksandr,
Thank you for contacting Infragistics Developer Support.
If you want to rotate the box chart horizontally, you could handle the FillSceneGraph event and get the GraphicsContext primitive. This primitive is basically responsible for drawing the rest of the primitives and it has a transform property. You can use this property to rotate the chart drawing (you need to rotate it by 90 degrees and translate its Y coordinate with the chart height). This way the chart will be rotated. Another thing you should do is to use the Y2 axis instead of the Y axis as when rotated, the Y2 axis will be in the place of the X axis. Also in order for the whole chart to be displayed after the rotation you should use a chart with equal height and width.
I have attached a sample in order to demonstrate this approach.
Please let me know if you have any additional questions.
It worked fine, thanks a lot! But now when I am trying to make it wider the height of control is also increases. So I can't make it for example Height 70 px and width 500 px. Can you suggest something?
Also I have several questions regarding different charts layout:
1. What it takes to get rid of gradient for bars and make it painted with solid color?
2. Is there any way to move "Data values on chart" so they will be not on the edge of bar(one digit inside the bar and another outside) but whole value inside the bar or outside?
3. Also this solution
foreach (Primitive item in e.SceneGraph)
{
Text pl = item as Text;
if (pl != null && pl.Path == "Border.Title.Grid.Y") {
pl.bounds.Offset(-15, 0); }
if (pl != null && pl.Path == "Border.Title.Grid.X") { pl.PE.Fill = Color.Green; pl.bounds.Offset(5, 15); } }
worked fine for lot of charts except for "Column chart"
Is there a way to move X Axis labels for "Column chart"?
Any help will be much appreciated.
P.S. I couldn't open solution that you attached. It looks like it was because I use VS 2010. If it is possible to attach solution that was built in the same studio it would be great. Thanks again.
Also here is my original sample in VS2010.
Hello Dimitar,
you helped me a lot, many thanks! But one thing I didn't managed to do anyway. It is to move X Axis labels to the right in the Column Chart. I have tried margin, it didn't helped, or maybe I used it in the wrong way. Also tried solution that I have described in the previous post - same result.
And one more little thing. Is there a way to show drop-lines for data points on this kind of chart?
Thanks in advance!
Hi Oleksandr,
Thanks you for the reply.
Yes, when using the ColumnChart the Path for text primitives for the axis labels have null value. So if you want to move them to the left you can try to recognize them by getting all the axis labels and checking if the text primitive is contained inside those labels. You can use code like this in the FillSceneGraph:
var textPrims = e.SceneGraph.OfType<Text>().ToList();
foreach (var text in textPrims)
var xAxis = e.Grid["X"] as SetLabelAxis;
if (xAxis == null)
return;
var labels = new List<string>();
for (int i = 0; i < xAxis.ChartData.GetColumnCount(); i++)
labels.Add(xAxis.ChartData.GetColumnLabel(i).ToString());
}
if (labels.Contains(text.GetTextString()))
text.bounds.Offset(20, 15);
As for the drop lines you could again use the FillSceneGraph event and add line primitives for the drop lines. You need to get the X and Y axes and then use their Map methods in order to determine the coordinates of the drop lines.
I have attached a sample demonstrating how to add the drop lines. For it I used a normal scatter chart.
Thanks a lot Dimitar, it was very helpfull!
Best regards.
once again I need your help.
1) I am using Composite histogram chart that you provided and I am trying to set ColumnSapcing property to 0. I tried to use this solution but it didn't work for me
ColumnChartAppearance appearance = new ColumnChartAppearance();
appearance.ColumnSpacing = 0;
myColumnLayer.ChartTypeAppearance = appearance;
The whole code for chart I use is:
public CombinedChart() { InitializeComponent(); }
private void CombinedChart_Load(object sender, EventArgs e) { this.ultraChart1.ChartType = ChartType.Composite;
ChartArea area = new ChartArea(); this.ultraChart1.CompositeChart.ChartAreas.Add(area);
AxisItem axisY = new AxisItem(); axisY.Extent = 20; axisY.DataType = AxisDataType.Numeric; axisY.Labels.ItemFormatString = "<DATA_VALUE:##.##>"; axisY.OrientationType = AxisNumber.Y_Axis; axisY.LineColor = Color.Silver; area.Axes.Add(axisY);
AxisItem axisY2 = new AxisItem(); axisY2.Extent = 20; axisY2.DataType = AxisDataType.Numeric; axisY2.Labels.ItemFormatString = "<DATA_VALUE:##.##>"; axisY2.OrientationType = AxisNumber.Y_Axis; axisY2.Visible = false; axisY2.LineColor = Color.Silver; area.Axes.Add(axisY2);
AxisItem axisX = new AxisItem(); axisX.Extent = 20; axisX.DataType = AxisDataType.String; axisX.Labels.Orientation = TextOrientation.VerticalLeftFacing; axisX.Labels.ItemFormatString = "<ITEM_LABEL>"; axisX.OrientationType = AxisNumber.X_Axis; axisX.SetLabelAxisType = SetLabelAxisType.GroupBySeries; axisX.LineColor = Color.Silver; area.Axes.Add(axisX);
AxisItem axisX1 = new AxisItem(); axisX1.Extent = 20; axisX1.DataType = AxisDataType.String; axisX1.Labels.Orientation = TextOrientation.VerticalLeftFacing; axisX1.Labels.ItemFormatString = "<ITEM_LABEL>"; axisX1.Labels.Visible = false; axisX1.OrientationType = AxisNumber.X_Axis; axisX1.SetLabelAxisType = SetLabelAxisType.ContinuousData; axisX1.LineColor = Color.Silver; area.Axes.Add(axisX1);
ChartLayerAppearance myColumnLayer = new ChartLayerAppearance(); myColumnLayer.ChartType = ChartType.ColumnChart; myColumnLayer.SwapRowsAndColumns = true; myColumnLayer.ChartArea = area;
ChartLayerAppearance myLineLayer = new ChartLayerAppearance(); myLineLayer.ChartType = ChartType.LineChart; myLineLayer.ChartArea = area;
DataTable dt = new DataTable(); dt.Columns.Add("Month"); dt.Columns.Add("Cumm Plane"); dt.Columns.Add("Monthly Achieve"); dt.Rows.Add("Apr-10", 1.039381, 0.00); dt.Rows.Add("May-10", 1.531703, 0.00); dt.Rows.Add("Jun-10", 2.166947, 2.50); dt.Rows.Add("Jul-10", 2.943036, 4.00); dt.Rows.Add("Aug-10", 3.837218, 3.20); dt.Rows.Add("Sep-10", 4.802984, 4.10); dt.Rows.Add("Oct-10", 5.771378, 4.70); dt.Rows.Add("Nov-10", 6.657660, 6.70); dt.Rows.Add("Dec-10", 7.372884, 6.70); dt.Rows.Add("Jan-11", 7.838389, 8.20); dt.Rows.Add("Feb-11", 8.000000, 8.30); dt.Rows.Add("Mar-11", 7.838389, 7.90); dt.Rows.Add("Apr-11", 7.372884, 6.80); dt.Rows.Add("May-11", 6.657660, 5.70); dt.Rows.Add("Jun-11", 5.771378, 5.40); dt.Rows.Add("Jul-11", 4.802984, 5.70); dt.Rows.Add("Aug-11", 3.837218, 5.20); dt.Rows.Add("Sep-11", 2.943036, 5.10); dt.Rows.Add("Nov-11", 2.166947, 4.60); dt.Rows.Add("Dec-11", 1.531703, 3.20);
NumericSeries series2 = new NumericSeries(); series2.DataBind(dt, "Monthly Achieve", "Month"); series2.PEs.Add(new PaintElement(Color.DimGray)); myColumnLayer.Series.Add(series2); ultraChart1.CompositeChart.Series.Add(series2); NumericSeries series3 = new NumericSeries(); series3.DataBind(dt, "Cumm Plane", "Month"); series3.PEs.Add(new PaintElement(Color.Red)); myLineLayer.Series.Add(series3); ultraChart1.CompositeChart.Series.Add(series3);
for (int i = 1; i < dt.Rows.Count; i++) { Override colorOverride = new Override(); colorOverride.Column = -2; colorOverride.Row = i; colorOverride.PE = new PaintElement(Color.LightSlateGray); this.ultraChart1.Override.Add(colorOverride); }
ColumnChartAppearance appearance = new ColumnChartAppearance(); appearance.ColumnSpacing = 0; myColumnLayer.ChartTypeAppearance = appearance;
myLineLayer.AxisX = axisX1; myLineLayer.AxisY = axisY2; this.ultraChart1.CompositeChart.ChartLayers.Add(myLineLayer);
myColumnLayer.AxisX = axisX; myColumnLayer.AxisY = axisY; this.ultraChart1.CompositeChart.ChartLayers.Add(myColumnLayer); }
private void ultraChart1_FillSceneGraph(object sender, Infragistics.UltraChart.Shared.Events.FillSceneGraphEventArgs e) { foreach (Primitive p in e.SceneGraph) { Box bar = p as Box; if (bar != null) { bar.PE.Stroke = Color.LightGray; } } }
2) The second question is regarding droplines.
The solution that you have provided works fine for ScatteredChart, but is there a way to use it for SplineChart?
3) The third is regarding value labels on chart.
You also provided the solution where these labels could be inside or outside the bar. But what I need is to decide in runtime where to place these value labels basing on the width of the bar. So if for example bar is too small I will need to place value label outside the bar and if the bar is very large I would have to place whole value label inside the bar. So the question is can I measure the width of particular bar to decide where to place label or maybe there is more fancy solution for this?
P.S. is there a way to attach my solution here?
Hello, Dimitar. I am not sure if you saw my questions so I will duplicate them here if you don't mind
1)
Hello, I have another issue with the code above. The problem is with the Override object herefor (int i = 0; i < GetHistogramData().Rows.Count; i++){Override colorOverride = new Override();colorOverride.Column = -2;colorOverride.Row = i;colorOverride.PE = new PaintElement(Color.LightSlateGray);this.ultraChart1.Override.Add(colorOverride);}
what I want is that Line chart to be red collor and Column chart to be LightSlateGray. But when I use override for
colorOverride.Column = 0;
colorOverride.Row = 0;
it colors first column of column chart and whole line chart in the same color. So when I get Override through the foreach loop all columns in the column chart (it is desirable) and whole line chart (not desirable) have the same color, colors are merged and it is impossible to see the line when columns are on the background.
Is there a way to set different color for the line?
I was trying to do something like this but it didn't helped
for (int i = 0; i < GetHistogramData().Rows.Count; i++){Override colorOverrideline = new Override();colorOverrideline.Column = -2;colorOverrideline.Row = i;colorOverrideline.PE = new PaintElement(Color.Red);myLineLayer.ChartComponent.Override.Add(colorOverrideline);}
It colors whole control anyway
I also checked ZeroAlignData property via designer. BTW where can I find this property in the code?
2) Also while using column chart in ultraChart1_FillSceneGraph event I was able to get var axisX = e.Grid["X"] as IAdvanceAxis; but now when I use composite chart I get null here.
The same thing with labels angle. When I was using column chart I was able to set Axis.X.Labels.Orientation = Custom and than set angle of labels. Using composite chart this property takes no effect.
Can you advice something?
Thanks!
Sorry I guess I confused this topic with this one http://es.infragistics.com/community/forums/p/92468/457865.aspx#457865.
Also while using column chart in ultraChart1_FillSceneGraph event I was able to get var axisX = e.Grid["X"] as IAdvanceAxis; but now when I use composite chart I get null here.
Thanks
for (int i = 0; i < GetHistogramData().Rows.Count; i++) { Override colorOverrideline = new Override(); colorOverrideline.Column = -2; colorOverrideline.Row = i; colorOverrideline.PE = new PaintElement(Color.Red); myLineLayer.ChartComponent.Override.Add(colorOverrideline); }
Thanks.
Thanks! I missed this line.
It seems that Mike has responded to you in this forum thread:
http://es.infragistics.com/community/forums/p/92739/459314.aspx#459314
You need to bind the different series to the different data sources. The sample code you have provided is doing just that. You only need to add one small modification – change the following line (which is right after you initialize the histogramSeries):
histogramSeries.DataBind(GetHistogramData(), "Monthly Achieve");
to:
histogramSeries.DataBind(GetHistogramData(),"Value", "Month");
After doing that I was able to run your sample and the chart was with 9 columns and a line consisting of 20 points.
I am looking forward to your reply.