Hello,
I have a question regarding histogram chart. The thing is that I already have a histogram data and I don't want to provide whole data set to calculate values on Y axis.
What I need is to show columns that on X axis will be measured with range values (like HistogramChart.ColumnAppearance.StringAxis = false), and on Y axis I just want to set my custom value for particular column.
Is it possible?
Thanks in advance
You can implement composite charts by creating a series for each chart type you want and having them share the same axes. For a good example of this, please see our Composite Chart sample in our online help.
http://help.infragistics.com/doc/WinForms/2014.2/CLR4.0/?page=Chart_Creating_a_Composite_Chart_in_Code_Part_2_of_2.html
Each series you have includes a DataSource property that you can use to bind to your data, like a Datatable
Let me know if you need any assistance getting started or have any questions.
Hello, thanks but I think I will use workaround with column chart and just move labels.
I wanted to ask other thing. Is there a way to combine column chart and line chart in the way that I can provide data for each chart separately. So for Line chart for example I want to show 20 points and for column chart only 9 columns.
There is a code that I want to use but I see empty screen:
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using Infragistics.UltraChart.Core.Layers;using Infragistics.UltraChart.Core.Primitives;using Infragistics.UltraChart.Resources.Appearance;using Infragistics.UltraChart.Shared.Styles;
namespace UltraChartLineChart.Charts{ public partial class CombinedChart : Form { public CombinedChart() { InitializeComponent(); }
private void CombinedChart_Load(object sender, EventArgs e) { this.ultraChart1.ChartType = ChartType.Composite;
ChartArea histogramArea = new ChartArea(); ChartArea lineArea = new ChartArea(); this.ultraChart1.CompositeChart.ChartAreas.Add(histogramArea); this.ultraChart1.CompositeChart.ChartAreas.Add(lineArea);
AxisItem axisYhistogram = new AxisItem(); axisYhistogram.Extent = 20; axisYhistogram.DataType = AxisDataType.Numeric; axisYhistogram.Labels.ItemFormatString = "<DATA_VALUE:##.##>"; axisYhistogram.OrientationType = AxisNumber.Y_Axis; axisYhistogram.LineColor = Color.Silver; histogramArea.Axes.Add(axisYhistogram);
AxisItem axisXhistogram = new AxisItem(); axisXhistogram.Extent = 20; axisXhistogram.DataType = AxisDataType.String; axisXhistogram.Labels.Orientation = TextOrientation.VerticalLeftFacing; axisXhistogram.Labels.ItemFormatString = "<ITEM_LABEL>"; axisXhistogram.OrientationType = AxisNumber.X_Axis; axisXhistogram.SetLabelAxisType = SetLabelAxisType.GroupBySeries; axisXhistogram.LineColor = Color.Silver; histogramArea.Axes.Add(axisXhistogram);
AxisItem axisYnormalDistribution = new AxisItem(); axisYnormalDistribution.Extent = 20; axisYnormalDistribution.DataType = AxisDataType.Numeric; axisYnormalDistribution.Labels.ItemFormatString = "<DATA_VALUE:##.##>"; axisYnormalDistribution.OrientationType = AxisNumber.Y_Axis; axisYnormalDistribution.Visible = false; axisYnormalDistribution.LineColor = Color.Silver; lineArea.Axes.Add(axisYnormalDistribution);
AxisItem axisXnormalDistribution = new AxisItem(); axisXnormalDistribution.Extent = 20; axisXnormalDistribution.DataType = AxisDataType.String; axisXnormalDistribution.Labels.Orientation = TextOrientation.VerticalLeftFacing; axisXnormalDistribution.Labels.ItemFormatString = "<ITEM_LABEL>"; axisXnormalDistribution.Labels.Visible = false; axisXnormalDistribution.OrientationType = AxisNumber.X_Axis; axisXnormalDistribution.SetLabelAxisType = SetLabelAxisType.ContinuousData; axisXnormalDistribution.LineColor = Color.Silver; lineArea.Axes.Add(axisXnormalDistribution);
ChartLayerAppearance myColumnLayer = new ChartLayerAppearance(); myColumnLayer.ChartType = ChartType.ColumnChart; myColumnLayer.SwapRowsAndColumns = true; myColumnLayer.ChartArea = histogramArea;
ChartLayerAppearance myLineLayer = new ChartLayerAppearance(); myLineLayer.ChartType = ChartType.LineChart; myLineLayer.ChartArea = lineArea;
NumericSeries histogramSeries = new NumericSeries(); histogramSeries.DataBind(GetHistogramData(), "Monthly Achieve"); histogramSeries.PEs.Add(new PaintElement(Color.DimGray)); myColumnLayer.Series.Add(histogramSeries); ultraChart1.CompositeChart.Series.Add(histogramSeries);
NumericSeries normalDestributionSeries = new NumericSeries(); normalDestributionSeries.DataBind(GetNormalDestributionData(), "Cumm Plane", "Month"); normalDestributionSeries.PEs.Add(new PaintElement(Color.Red)); myLineLayer.Series.Add(normalDestributionSeries); ultraChart1.CompositeChart.Series.Add(normalDestributionSeries);
for (int i = 1; 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); }
ColumnChartAppearance appearance = new ColumnChartAppearance(); appearance.SeriesSpacing = 0; myColumnLayer.ChartTypeAppearance = appearance;
myColumnLayer.AxisX = axisXhistogram; myColumnLayer.AxisY = axisYhistogram; this.ultraChart1.CompositeChart.ChartLayers.Add(myColumnLayer);
myLineLayer.AxisX = axisXnormalDistribution; myLineLayer.AxisY = axisYnormalDistribution; this.ultraChart1.CompositeChart.ChartLayers.Add(myLineLayer); }
private DataTable GetHistogramData() { DataTable lineDt = new DataTable(); lineDt.Columns.Add("Month"); lineDt.Columns.Add("Value", typeof(decimal));
lineDt.Rows.Add("Apr-10", 1.039381); lineDt.Rows.Add("May-10", 1.531703); lineDt.Rows.Add("Jun-10", 2.166947); lineDt.Rows.Add("Jul-10", 2.943036); lineDt.Rows.Add("Aug-10", 3.837218); lineDt.Rows.Add("Sep-10", 4.802984); lineDt.Rows.Add("Oct-10", 5.771378); lineDt.Rows.Add("Nov-10", 6.657660); lineDt.Rows.Add("Dec-10", 7.372884);
return lineDt; } private DataTable GetNormalDestributionData() { DataTable lineDt = new DataTable(); lineDt.Columns.Add("Month"); lineDt.Columns.Add("Cumm Plane", typeof(decimal));
lineDt.Rows.Add("Apr-10", 1.039381); lineDt.Rows.Add("May-10", 1.531703); lineDt.Rows.Add("Jun-10", 2.166947); lineDt.Rows.Add("Jul-10", 2.943036); lineDt.Rows.Add("Aug-10", 3.837218); lineDt.Rows.Add("Sep-10", 4.802984); lineDt.Rows.Add("Oct-10", 5.771378); lineDt.Rows.Add("Nov-10", 6.657660); lineDt.Rows.Add("Dec-10", 7.372884); lineDt.Rows.Add("Jan-11", 7.838389); lineDt.Rows.Add("Feb-11", 8.000000); lineDt.Rows.Add("Mar-11", 7.838389); lineDt.Rows.Add("Apr-11", 7.372884); lineDt.Rows.Add("May-11", 6.657660); lineDt.Rows.Add("Jun-11", 5.771378); lineDt.Rows.Add("Jul-11", 4.802984); lineDt.Rows.Add("Aug-11", 3.837218); lineDt.Rows.Add("Sep-11", 2.943036); lineDt.Rows.Add("Nov-11", 2.166947); lineDt.Rows.Add("Dec-11", 1.531703);
return lineDt; }
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; } } } }}
The X axis I want to use only for column chart labels
Hello Oleksandr,
I converted and attached a VS 2010 sample project.
I have opened a private case for you so we can continue our discussion. There I will be requesting for additional information. The case number is CAS-145768-T7L2Z0. You will see it located here: https://es.infragistics.com/my-account/support-activity
If you have any questions please update your case.
Unfortunately it is not what I meant. The X axis in original histogram works fine for me, the problem is with Y axis. In your sample the height of columns will be calculated based on amount of same values in array { 1, 9, 13, 5, 6, 7, 8, 9, 9, 9, 12, 13, 14, 15, 16 }; For example "9" digit is present 4 times. But in my data I already have the amount of particular values and
I just want to provide for example value=9; count=4; and get the result on Y axis as if I provided "9" digit four times in array.
P.S. I have VS 2010 and can't open your attachment
I attached a sample that achieves your requirements.
1. You should be able to set the RangeMax for the Yaxis to be the count of items in your datasource. eg.
this.ultraChart1.Axis.Y.RangeMax = intArray.Count();
2. In order to set the range to be on the Xaxis and have them displayed horizontal you can create a class that implements IRenderLabel and customize the labels that way. Then you can set the Orientation property to Horizontal
eg. //Rotate the labels this.ultraChart1.Axis.X.Labels.Orientation = TextOrientation.Horizontal;
...FormLoad
this.ultraChart1.Axis.X.Labels.ItemFormatString = "<MY_VALUE>"; Hashtable MyLabelHashTable = new Hashtable(); MyLabelHashTable.Add("MY_VALUE", new MyLabelRenderer()); this.ultraChart1.LabelHash = MyLabelHashTable;
...end
public class MyLabelRenderer : IRenderLabel { public string ToString(Hashtable context) { double dataValue = (double)context["DATA_VALUE"]; if (dataValue == 20) return "20-25"; else if (dataValue == 15) return "15-20"; else if (dataValue == 10) return "10-15"; else if (dataValue == 5) return "5-10"; else return "0-5"; } }
For more details about this interface, please visit our documentation page: http://help.infragistics.com/doc/WinForms/2014.2/CLR4.0/?page=Chart_Customize_Labels_Using_the_IRenderLabel_Interface.html
Another chart type won't be necessary if you choose to use this implementation.
Let me know if you have any questions.