Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
515
Composite Webchart Y-axis starts from 0
posted

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: