Ticket T270231
Visible to All Users

Hide zero level on Y-Axis in chart

created 10 years ago (modified 10 years ago)

Hi
I am creating a line chart on a win form where y axis does not show zero level. I have tried setting diagram.AxisY.WholeRange.AlwaysShowZeroLevel = false and setting min max range, nothing seems to work so far. Could you please help.
I have attached a sample project that has  this issue. Please take a look. I am working on version 14.1

C#
private void Form1_Load(object sender, EventArgs e) { // Create a chart control. //ChartControl chartControl1 = new ChartControl(); // Add the chart to the form. //chartControl1.Dock = DockStyle.Fill; //this.Controls.Add(chartControl1); chartControl1.Series.Clear(); // Create a bar series and add points to it. Series series1 = new Series("Series 1", ViewType.Line); series1.ArgumentScaleType = ScaleType.DateTime; DateTime d1 = DateTime.Now; d1.AddDays(-1); series1.Points.Add(new SeriesPoint(d1, new double[] { 26.25 })); series1.Points.Add(new SeriesPoint(d1.AddDays(2), new double[] { 1.52 })); series1.Points.Add(new SeriesPoint(d1.AddDays(3), new double[] { 22.21 })); series1.Points.Add(new SeriesPoint(d1.AddDays(4), new double[] { 15.35 })); series1.Points.Add(new SeriesPoint(d1.AddDays(5), new double[] { 4.15 })); // Add the series to the chart. chartControl1.Series.Add(series1); // Cast the chart's diagram to the XYDiagram type, to access its axes. XYDiagram diagram = (XYDiagram)chartControl1.Diagram; // Enable the diagram's scrolling. diagram.EnableAxisXScrolling = true; diagram.EnableAxisYScrolling = true; // Define the whole range for the X-axis. diagram.AxisX.WholeRange.Auto = true; //diagram.AxisX.WholeRange.SetMinMaxValues("A", "D"); // Disable the side margins // (this has an effect only for certain view types). diagram.AxisX.VisualRange.AutoSideMargins = false; // Limit the visible range for the X-axis. diagram.AxisX.VisualRange.Auto = true; //diagram.AxisX.VisualRange.SetMinMaxValues("B", "C"); // Define the whole range for the Y-axis. diagram.AxisY.WholeRange.Auto = false; diagram.AxisY.WholeRange.AlwaysShowZeroLevel = true; diagram.AxisY.WholeRange.SetMinMaxValues(1, 26.25 ); } Edit 1: Series series1 = new Series("Series 1", ViewType.Line); series1.ArgumentScaleType = ScaleType.DateTime; series1.ValueScaleType = ScaleType.Numerical; series1.Points.Add(new SeriesPoint(new DateTime(2015,9,15),15 )); series1.Points.Add(new SeriesPoint(new DateTime(2016, 9, 15), 10)); series1.Points.Add(new SeriesPoint(new DateTime(2017, 7, 15), 21)); series1.Points.Add(new SeriesPoint(new DateTime(2018, 9, 15), 16)); series1.Points.Add(new SeriesPoint(new DateTime(2020, 5, 15), 600)); // Add the series to the chart. chartControl1.Series.Add(series1); // Cast the chart's diagram to the XYDiagram type, to access its axes. XYDiagram diagram = (XYDiagram)chartControl1.Diagram; // Enable the diagram's scrolling. diagram.EnableAxisXScrolling = false; diagram.EnableAxisYScrolling = false; // Define the whole range for the X-axis. diagram.AxisX.WholeRange.Auto = false; diagram.AxisX.Label.TextPattern = "{A:d}"; diagram.AxisX.WholeRange.SetMinMaxValues(new DateTime(2015,5,15), new DateTime(2021, 5, 15)); // Disable the side margins // (this has an effect only for certain view types). diagram.AxisX.VisualRange.AutoSideMargins = false; // Limit the visible range for the X-axis. diagram.AxisX.VisualRange.Auto = false; //diagram.AxisX.VisualRange.SetMinMaxValues("B", "C"); // Define the whole range for the Y-axis. //diagram.AxisY.WholeRange.Auto = false; diagram.AxisY.WholeRange.SideMarginsValue = 0; diagram.AxisY.WholeRange.SetMinMaxValues(5, 650);

Answers approved by DevExpress Support

created 10 years ago (modified 10 years ago)

Hi Sabuj,

To solve this issue, disable the automatic side margin value by setting the SideMarginsValue property to zero.

C#
diagram.AxisY.WholeRange.SideMarginsValue = 0; diagram.AxisY.WholeRange.SetMinMaxValues(126.25 );

    Show previous comments (12)
    DevExpress Support Team 10 years ago

      Attached is an updated sample project that produces the correct axis label layout in my tests. Let me know how it works for you.

        Thanks Alex. it worked

        DevExpress Support Team 10 years ago

          You are always welcome!

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.