示例#1
0
        private void WriteValueLabels(GraphPane pane, BarItem bar,
                                      string fontFamily, float fontSize, bool isNegative)
        {
            //shrink the bar font just a little
            fontSize -= 1;

            double xMin, xMax;
            double yMin, yMax;

            bar.GetRange(out xMin, out xMax, out yMin, out yMax, false, false, pane);

            //adjust singular values so that the label doesn't bleed into the bar
            if (isNegative)
            {
                yMax = Math.Max(yMax, 0);
            }
            else
            {
                yMin = Math.Min(yMin, 0);
            }

            double difference = Math.Abs(yMax - yMin);
            double offset     = bar.Points.Count == 1 ?
                                0.05 * difference :
                                0.1 * difference;

            for (int i = 0; i < bar.Points.Count; i++)
            {
                PointPair pt = bar.Points[i];
                if (pt.Y == 0.0)
                {
                    continue;
                }

                double myOffset = pt.Y > 0 ? offset : -offset;
                double myShift  = pt.Y > 0 ? 0.75 : 0.65;

                string label = pt.Y.ToString("f2") + "%";

                // Create a text label from the Y data value
                TextObj text = new TextObj(label, (i + myShift), pt.Y + myOffset,
                                           CoordType.AxisXYScale, AlignH.Left, AlignV.Center);

                text.FontSpec.Family = fontFamily;
                text.FontSpec.Size   = fontSize;

                text.FontSpec.Angle            = 0;
                text.FontSpec.Border.IsVisible = false;
                text.FontSpec.Fill.IsVisible   = false;

                text.Location.AlignH          = AlignH.Left;
                text.Location.AlignV          = AlignV.Center;
                text.Location.CoordinateFrame = CoordType.AxisXYScale;

                text.ZOrder = ZOrder.A_InFront;

                pane.GraphObjList.Add(text);
            }
        }