Hi,
I have a composite webchart which is column and line chart. When both Y-axis have data, Y-axis starts from 0. However, when there is no data on one of Y-axis, the Y-axis doesn't start from 0. How can I force it to start from 0. Below are my code and images. What can I do?
Code:
*************************************************************************
#region Define Chart Type and create ChartArea this.UltraChart1.ChartType = ChartType.Composite; ChartArea myChartArea = new ChartArea(); this.UltraChart1.CompositeChart.ChartAreas.Add(myChartArea); #endregion
#region column layers use a string, GroupBySeries x axis AxisItem xAxisColumn = new AxisItem(UltraChart1, AxisNumber.X_Axis); xAxisColumn.DataType = AxisDataType.String; xAxisColumn.SetLabelAxisType = SetLabelAxisType.GroupBySeries;
//xAxisColumn.Labels.ItemFormatString = "<ITEM_LABEL>"; xAxisColumn.Labels.SeriesLabels.Format = AxisSeriesLabelFormat.SeriesLabel; xAxisColumn.Labels.SeriesLabels.FormatString = "<SERIES_LABEL>"; xAxisColumn.LineThickness = 1; xAxisColumn.Labels.SeriesLabels.Orientation = TextOrientation.VerticalLeftFacing; xAxisColumn.Margin.Far.Value = 0; xAxisColumn.Extent = 130; myChartArea.Axes.Add(xAxisColumn); #endregion
#region line layers use a string, ContinuousData x axis AxisItem xAxisLine = new AxisItem(UltraChart1, AxisNumber.X_Axis); xAxisLine.DataType = AxisDataType.String;
xAxisLine.SetLabelAxisType = SetLabelAxisType.ContinuousData;
xAxisLine.LineThickness = 1; xAxisLine.Labels.SeriesLabels.Orientation = TextOrientation.VerticalLeftFacing; xAxisLine.Margin.Near.MarginType = LocationType.Percentage; xAxisLine.Margin.Near.Value = 0; xAxisLine.Margin.Far.MarginType = LocationType.Percentage; xAxisLine.Margin.Far.Value = 0; xAxisLine.Extent = 130; xAxisColumn.MajorGridLines.Visible = false; myChartArea.Axes.Add(xAxisLine);
AxisItem xAxis2 = new AxisItem(UltraChart1, AxisNumber.X2_Axis); xAxis2.Extent = 50; xAxis2.LineThickness = 1; xAxis2.MajorGridLines.Visible = false; myChartArea.Axes.Add(xAxis2); #endregion
#region Create Y Axis AxisItem yAxis = new AxisItem(UltraChart1, AxisNumber.Y_Axis); yAxis.DataType = AxisDataType.Numeric; yAxis.Labels.ItemFormat = AxisItemLabelFormat.DataValue; yAxis.Labels.ItemFormatString = "<DATA_VALUE:00.##>"; yAxis.LineThickness = 1; yAxis.TickmarkStyle = AxisTickStyle.Smart; yAxis.Extent = 50; yAxis.RangeMin = 0; //yAxis.RangeMax = 1.0; yAxis.RangeType = AxisRangeType.Automatic; myChartArea.Axes.Add(yAxis);
AxisItem yAxis2 = new AxisItem(UltraChart1, AxisNumber.Y2_Axis); yAxis2.DataType = AxisDataType.Numeric; yAxis2.Labels.ItemFormat = AxisItemLabelFormat.DataValue; yAxis2.Labels.ItemFormatString = "<DATA_VALUE>"; yAxis2.LineThickness = 1; yAxis2.TickmarkStyle = AxisTickStyle.Smart; yAxis2.Margin.Far.Value = 0; yAxis2.Extent = 50; yAxis2.MajorGridLines.Visible = false; yAxis2.RangeMin = 0; yAxis.RangeType = AxisRangeType.Automatic; myChartArea.Axes.Add(yAxis2); #endregion
#region Define Series NumericSeries seriesColumn1 = new NumericSeries(); seriesColumn1.Data.DataSource = columnAndLineChartDataTable; seriesColumn1.Label = columnAndLineChartDataTable.Columns[1].ColumnName; seriesColumn1.Data.LabelColumn = columnAndLineChartDataTable.Columns[0].ColumnName; seriesColumn1.Data.ValueColumn = columnAndLineChartDataTable.Columns[1].ColumnName;
UltraChart1.CompositeChart.Series.Add(seriesColumn1); seriesColumn1.PEs.Add(new PaintElement(Color.DeepSkyBlue));
NumericSeries seriesLine1 = new NumericSeries(); seriesLine1.Data.DataSource = columnAndLineChartDataTable; seriesLine1.Label = ListBoxRightY.SelectedItem.Text; seriesLine1.Data.LabelColumn = columnAndLineChartDataTable.Columns[0].ColumnName; if (columnAndLineChartDataTable.Columns[2].ColumnName.Contains("Year-Month")) seriesLine1.Data.ValueColumn = columnAndLineChartDataTable.Columns[3].ColumnName; else seriesLine1.Data.ValueColumn = columnAndLineChartDataTable.Columns[2].ColumnName;
UltraChart1.CompositeChart.Series.Add(seriesLine1); seriesLine1.PEs.Add(new PaintElement(Color.DarkOrange)); #endregion
#region Define StackColumnLayer/LineLayer ChartLayerAppearance columnLayer = new ChartLayerAppearance(); columnLayer.AxisX = xAxisColumn; columnLayer.AxisY = yAxis; columnLayer.ChartArea = myChartArea; columnLayer.ChartType = ChartType.ColumnChart; columnLayer.Series.Add(seriesColumn1); columnLayer.SwapRowsAndColumns = true; UltraChart1.CompositeChart.ChartLayers.Add(columnLayer);
ChartLayerAppearance lineLayer = new ChartLayerAppearance(); lineLayer.AxisX = xAxisLine; lineLayer.AxisY = yAxis2; lineLayer.ChartArea = myChartArea; lineLayer.ChartType = ChartType.LineChart; lineLayer.Series.Add(seriesLine1); UltraChart1.CompositeChart.ChartLayers.Add(lineLayer);
LineAppearance lineApp = new LineAppearance(); lineApp.IconAppearance.Icon = SymbolIcon.Diamond; lineApp.IconAppearance.IconSize = SymbolIconSize.Medium; lineApp.LineStyle.StartStyle = LineCapStyle.NoAnchor; lineApp.LineStyle.EndStyle = LineCapStyle.NoAnchor; LineChartAppearance lineChartAppearance = new LineChartAppearance(); lineChartAppearance.LineAppearances.Add(lineApp);
lineLayer.ChartTypeAppearance = lineChartAppearance; UltraChart1.LineChart.NullHandling = NullHandling.DontPlot; #endregion
#region Add a legend to the chart CompositeLegend myLegend = new CompositeLegend(); myLegend.ChartLayers.Add(columnLayer); myLegend.ChartLayers.Add(lineLayer); myLegend.Bounds = new Rectangle(40, 88, 40, 10); myLegend.BoundsMeasureType = MeasureType.Percentage; myLegend.PE.ElementType = PaintElementType.Gradient; myLegend.PE.FillGradientStyle = GradientStyle.ForwardDiagonal; //myLegend.PE.Fill = Color.CornflowerBlue; myLegend.PE.FillStopColor = Color.Transparent; //myLegend.Border.CornerRadius = 20; myLegend.Border.Thickness = 1; UltraChart1.CompositeChart.Legends.Add(myLegend);
BoxAnnotation boxAnnotation = new BoxAnnotation(); boxAnnotation.Text = string.Format("{0} versus {1}", ListBoxLeftY.SelectedItem.Text, ListBoxRightY.SelectedItem.Text); boxAnnotation.Border.Color = Color.Orchid; boxAnnotation.Location.Type = LocationType.Pixels; boxAnnotation.Location.LocationX = 350; boxAnnotation.Location.LocationY = 25; boxAnnotation.TextStyle.Font = new Font(FontFamily.GenericSansSerif, 10F, FontStyle.Bold); this.UltraChart1.Annotations.Annotations.Add(boxAnnotation); this.UltraChart1.TitleTop.Visible = false;
#endregion
#region Add title to chart this.UltraChart1.TitleLeft.Text = ListBoxLeftY.SelectedItem.Text; this.UltraChart1.TitleRight.Text = ListBoxRightY.SelectedItem.Text; this.UltraChart1.TitleLeft.Visible = true; this.UltraChart1.TitleRight.Visible = true; this.UltraChart1.TitleLeft.HorizontalAlign = StringAlignment.Center; this.UltraChart1.TitleRight.HorizontalAlign = StringAlignment.Center; this.UltraChart1.TitleLeft.VerticalAlign = StringAlignment.Near; this.UltraChart1.TitleRight.VerticalAlign = StringAlignment.Near; #endregion
#region Add DataPoint to ColumnChart Layer ChartTextAppearance myColumnChartText = new ChartTextAppearance(); myColumnChartText.ItemFormatString = "<DATA_VALUE:00.00>"; myColumnChartText.Column = myColumnChartText.Row = -2; myColumnChartText.FontColor = System.Drawing.Color.Tomato; myColumnChartText.VerticalAlign = StringAlignment.Far; myColumnChartText.HorizontalAlign = StringAlignment.Far; myColumnChartText.Visible = true;
ColumnChartAppearance columnApp = this.UltraChart1.CompositeChart.ChartLayers[0].ChartTypeAppearance as ColumnChartAppearance; columnApp.NullHandling = NullHandling.DontPlot; columnApp.ChartText.Add(myColumnChartText);
ChartTextAppearance myLineChartText = new ChartTextAppearance(); myLineChartText.ItemFormatString = "<DATA_VALUE:00.00>"; myLineChartText.Column = myLineChartText.Row = -2; myLineChartText.FontColor = System.Drawing.Color.Black; myLineChartText.VerticalAlign = StringAlignment.Far; myLineChartText.HorizontalAlign = StringAlignment.Far; myLineChartText.Visible = true; lineChartAppearance.ChartText.Add(myLineChartText); #endregion
this.UltraChart1.Data.ZeroAligned = true;
************************************************************************
Attached are my images:
Hello,
I am following up to see if you have any further questions with this matter?
Update me if any further assistance needed
Thanks,
Bhadresh
UltraChart.Data.ZeroAligned can be used for non-composite charts. If you are using a composite chart, the best way to do this is to set the X axis's Visible property to false, then draw a new line in the FillSceneGraph event, mapped at the Y axis 0 point The below link from our website will give you more details on this:
<http://news.infragistics.com/forums/t/5048.aspx>
You may modify the code shown on above link for axis. I have also logged a feature request FR13001 for UltraChart.Data.ZeroAligned for composite chart.
Hope this helps.
Any suggestions?
Thanks!
Sorry, wrong images. Image Chart_96.png is not correct. Here is the correct one:
Another Attachment: