Menu

Horizontal bar yaxis labels not visible

Help
2006-09-26
2012-09-19
  • Peter Oresnik

    Peter Oresnik - 2006-09-26

    I want to create horizontal oriented bar chart with labels placed on y-axis.

    How to make y axis labels visible for negative bar values? (See example: "bar two" is not visible, because bar draws over the label).

            GraphPane myPane = zgc.GraphPane;
    
            // Set the titles and axis labels
            myPane.Title.Text = "Axis Cross Demo";
            myPane.XAxis.Title.Text = "My X Axis";
            myPane.YAxis.Title.Text = "My Y Axis";
    
            // Make up some data arrays based on the Sine function
            double x, y;
            PointPairList list = new PointPairList();
            for (int i = 0; i < 4; i++)
            {
                x = (i - 2);
                y = i;
                list.Add(x, y);
            }
    
    
            // Generate a red curve with diamond
            // symbols, and "Porsche" in the legend
    

    // LineItem myCurve = myPane.AddCurve("Parabola", list, Color.Green, SymbolType.Diamond);

            PointPairList pptest = new PointPairList();
            for (int i = 0; i < 4; i++)
            {
    

    // pptest.Add(i - 2, i+1);
    }
    pptest.Add(0, 2);
    pptest.Add(1, 5);
    pptest.Add(2, 3);
    pptest.Add(3, 6);
    pptest.Add(4, 4);

            myPane.Y2Axis.IsVisible = false;
    

    / myPane.Y2AxisMin = 0;
    myPane.Y2Axis.Max = 4;
    /

            BarItem myBar = myPane.AddBar("Bar", pptest, Color.Blue);
            myBar.IsY2Axis = true;
    
            // Set the Y axis intersect the X axis at an X value of 0.0
            myPane.YAxis.Cross = 0.0;
            // Turn off the axis frame and all the opposite side tics
    

    / myPane.Chart.Border.IsVisible = false;
    myPane.XAxis.MajorTic.IsOpposite = false;
    myPane.XAxis.MinorTic.IsOpposite = false;
    myPane.YAxis.MajorTic.IsOpposite = false;
    myPane.YAxis.MinorTic.IsOpposite = false;
    /

            string[] labels = { "zero", "one", "two", "three", "four" };
    
            myPane.YAxis.Type = AxisType.Text;
            myPane.YAxis.Scale.TextLabels = labels;
    
            // Calculate the Axis Scale Ranges
            zgc.AxisChange();            
            zgc.Refresh();
    
     
    • Peter Oresnik

      Peter Oresnik - 2006-09-26

      Sorry wrong example :)

              GraphPane myPane = zgc.GraphPane;
              myPane.CurveList.Clear();
              PointPairList list = new PointPairList();
      
              list.Clear();
              list.Add(4, 0);
              list.Add(-2, 1);
              list.Add(5, 2);
              list.Add(3, 3);
              string[] labels = { "bar one", "bar two", "bar three", "bar four"};
              myPane.YAxis.Scale.TextLabels = labels;
              myPane.YAxis.Type = AxisType.Text;
      
              myPane.YAxis.Cross = 0.0;
      
              BarItem myCurve2 = myPane.AddBar("curve 2", list, Color.Red);
              myCurve2.Bar.Fill = new Fill(Color.Red, Color.White, Color.Red, 90);
      
              // Set BarBase to the YAxis for horizontal bars
              myPane.BarSettings.Base = BarBase.Y;
      
              zgc.AxisChange();
              zgc.Refresh();
      
       
    • John Champion

      John Champion - 2006-09-27

      Hi,
      Try commenting out the "Cross" setting, and adding a zero line like this:

      //myPane.YAxis.Cross = 0.0;
      myPane.XAxis.MajorGrid.IsZeroLine = true;

      John

       
    • Peter Oresnik

      Peter Oresnik - 2006-09-27

      Hi!

      Thank you for your answer.

      Setting IsZeroLine to true moves labels away from x=0 axis. I would like to have labels written in front of negative bar and labels pointing to x=0 (y) axis.

      Is that possible?

       

Log in to post a comment.

Auth0 Logo