How to specify location of an axis' tick mark labels RRS feed

  • Question

  • In a Forms application I have data, bipolar in x, that I plot in a chart.  I have managed to get the y-axis to cross at 0 on the x-axis, but I can not get the labels to stay outside the chart on the left side.  I tried the following, but the labels follow the axis:

                MRGraph.ChartAreas[0].AxisX.IsMarksNextToAxis = false;
                MRGraph.ChartAreas[1].AxisX.IsMarksNextToAxis = false;
                MRGraph.ChartAreas[0].AxisX.Crossing = 0;
                MRGraph.ChartAreas[1].AxisX.Crossing = 0;
                MRGraph.ChartAreas[0].AxisY.LabelStyle.Format = "{0:#.##e+0}";
                MRGraph.ChartAreas[1].AxisY.LabelStyle.Format = "{0:#.##e+0}";

    but the labels follow the axis, see figure.

    How can I move the y-axis labels outside the vertical grid line at x = -88?


    Friday, March 15, 2019 6:57 PM

All replies

  • Hi RBeech,

    If you're using System.Windows.Forms.DataVisualization.Charting, AxisY can be placed on the left or right.
      [my code in VB.NET]
      Chart1.ChartAreas(0).AxisY.IsReversed = False ' -- Left position
      Chart1.ChartAreas(0).AxisY.IsReversed = True ' -- Right

    But in a Bipolar chart, I'm afraid, AxisY is fixed on the center.
    How about using a Line chart?


    Ashidacchi -- https://ssl01.rocketnet.jp/hokusosha.com/default.html

    Friday, March 15, 2019 10:51 PM
  • Ashidacchi,

    Thanks for the reply.  Actually, by default AxisY is not in the center but is on the left side of the chart; it only appears in the center when I add "MRGraph.ChartAreas[0].AxisX.Crossing = 0;" to my code.  What I want is to have a vertical grid line at x=0, but with the axis/major tick labels staying on the left.  From the class documentation, it looked like setting IsMarksNextToAxis = false would leave the labels on the left, but it did not work for me.

    My data varies widely from plot to plot, so I use a RecalculateAxesScale() each time I change the data in the chart, but I can't figure out how to get this function to include a major grid line at x=0 (as can be seen in the example graph it evenly divides the x-axis from -Maximum to +Maximum and this does not put a major grid line at 0).



    Monday, March 18, 2019 12:17 PM
  • Hi RBeech,

    (1) Could you share your data file (Excel?, originally) via cloud storage such as OneDrive, Dropbox, etc?

    (2) What kind of chart type do you use?  I have never heard "bipolar".


    Ashidacchi -- https://ssl01.rocketnet.jp/hokusosha.com/default.html

    Tuesday, March 19, 2019 11:00 AM
  • Ashidacchi,

    It is the data that is bipolar.  This simply means that it has both positive and negative values and, therefore, the origin of the axis will be in the middle of the graph rather than at the edge.  The chart type is "Line" and the result, with default settings, looks like the example below: note that the y-axis is not positioned at x=0, but is instead on the left side of the chart.  I want the y-axis to be at x=0 (or at least have a vertical grid line at x=0), but with the labels still on the left.

    I could share some data - it is just two columns of data where the column to be used for the x-axis is bipolar - but I do not use cloud storage.


    Tuesday, March 19, 2019 12:02 PM