当前位置: 首页>>代码示例>>C#>>正文


C# ValueHandler.BarCenterValue方法代码示例

本文整理汇总了C#中ZedGraph.ValueHandler.BarCenterValue方法的典型用法代码示例。如果您正苦于以下问题:C# ValueHandler.BarCenterValue方法的具体用法?C# ValueHandler.BarCenterValue怎么用?C# ValueHandler.BarCenterValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ZedGraph.ValueHandler的用法示例。


在下文中一共展示了ValueHandler.BarCenterValue方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateBarLabels

		/// <summary>
		/// Create a <see cref="TextObj" /> for each bar in the <see cref="GraphPane" />.
		/// </summary>
		/// <remarks>
		/// This method will go through the bars, create a label that corresponds to the bar value,
		/// and place it on the graph depending on user preferences.  This works for horizontal or
		/// vertical bars in clusters or stacks, but only for <see cref="BarItem" /> types.  This method
		/// does not apply to <see cref="ErrorBarItem" /> or <see cref="HiLowBarItem" /> objects.
		/// Call this method only after calling <see cref="GraphPane.AxisChange()" />.
		/// </remarks>
		/// <param name="pane">The GraphPane in which to place the text labels.</param>
		/// <param name="isBarCenter">true to center the labels inside the bars, false to
		/// place the labels just above the top of the bar.</param>
		/// <param name="valueFormat">The double.ToString string format to use for creating
		/// the labels.
		/// </param>
		/// <param name="fontColor">The color in which to draw the labels</param>
		/// <param name="fontFamily">The string name of the font family to use for the labels</param>
		/// <param name="fontSize">The floating point size of the font, in scaled points</param>
		/// <param name="isBold">true for a bold font type, false otherwise</param>
		/// <param name="isItalic">true for an italic font type, false otherwise</param>
		/// <param name="isUnderline">true for an underline font type, false otherwise</param>
		public static void CreateBarLabels(GraphPane pane, bool isBarCenter, string valueFormat,
		                                   string fontFamily, float fontSize, Color fontColor, bool isBold, bool isItalic,
		                                   bool isUnderline)
		{
			bool isVertical = pane.BarSettings.Base == BarBase.X;

			// keep a count of the number of BarItems
			int curveIndex = 0;

			// Get a valuehandler to do some calculations for us
			ValueHandler valueHandler = new ValueHandler(pane, true);

			// Loop through each curve in the list
			foreach (CurveItem curve in pane.CurveList) {
				// work with BarItems only
				BarItem bar = curve as BarItem;
				if (bar != null) {
					IPointList points = curve.Points;

					// ADD JKB 9/21/07
					// The labelOffset should depend on whether the curve is YAxis or Y2Axis.
					// JHC - Generalize to any value axis
					// Make the gap between the bars and the labels = 1.5% of the axis range
					float labelOffset;

					Scale scale = curve.ValueAxis(pane).Scale;
					labelOffset = (float) (scale._max - scale._min)*0.015f;

					// Loop through each point in the BarItem
					for (int i = 0; i < points.Count; i++) {
						// Get the high, low and base values for the current bar
						// note that this method will automatically calculate the "effective"
						// values if the bar is stacked
						double baseVal, lowVal, hiVal;
						valueHandler.GetValues(curve, i, out baseVal, out lowVal, out hiVal);

						// Get the value that corresponds to the center of the bar base
						// This method figures out how the bars are positioned within a cluster
						float centerVal = (float) valueHandler.BarCenterValue(bar,
						                                                      bar.GetBarWidth(pane), i, baseVal, curveIndex);

						// Create a text label -- note that we have to go back to the original point
						// data for this, since hiVal and lowVal could be "effective" values from a bar stack
						string barLabelText = (isVertical ? points[i].Y : points[i].X).ToString(valueFormat);

						// Calculate the position of the label -- this is either the X or the Y coordinate
						// depending on whether they are horizontal or vertical bars, respectively
						float position;
						if (isBarCenter)
							position = (float) (hiVal + lowVal)/2.0f;
						else if (hiVal >= 0)
							position = (float) hiVal + labelOffset;
						else
							position = (float) hiVal - labelOffset;

						// Create the new TextObj
						TextObj label;
						if (isVertical)
							label = new TextObj(barLabelText, centerVal, position);
						else
							label = new TextObj(barLabelText, position, centerVal);

						label.FontSpec.Family = fontFamily;

						// Configure the TextObj

						// CHANGE JKB 9/21/07
						// CoordinateFrame should depend on whether curve is YAxis or Y2Axis.
						label.Location.CoordinateFrame =
							(isVertical && curve.IsY2Axis) ? CoordType.AxisXY2Scale : CoordType.AxisXYScale;

						label.FontSpec.Size = fontSize;
						label.FontSpec.FontColor = fontColor;
						label.FontSpec.IsItalic = isItalic;
						label.FontSpec.IsBold = isBold;
						label.FontSpec.IsUnderline = isUnderline;

						label.FontSpec.Angle = isVertical ? 90 : 0;
//.........这里部分代码省略.........
开发者ID:stewmc,项目名称:vixen,代码行数:101,代码来源:BarItem.cs

示例2: FindNearestPoint


//.........这里部分代码省略.........
                            if ( _xAxis._scale.IsAnyOrdinal && !curve.IsOverrideOrdinal )
                                xVal = (double)iPt + 1.0;
                            else
                                xVal = points[iPt].X;

                            // yVal is the user scale Y value of the current point
                            if ( yAxis._scale.IsAnyOrdinal && !curve.IsOverrideOrdinal )
                                yVal = (double)iPt + 1.0;
                            else
                                yVal = points[iPt].Y;

                            if ( xVal != PointPair.Missing &&
                                    yVal != PointPair.Missing )
                            {

                                if ( curve.IsBar || curve is ErrorBarItem ||
                                    curve is HiLowBarItem || curve is OHLCBarItem ||
                                    curve is JapaneseCandleStickItem )
                                {
                                    double baseVal, lowVal, hiVal;
                                    valueHandler.GetValues( curve, iPt, out baseVal,
                                            out lowVal, out hiVal );

                                    if ( lowVal > hiVal )
                                    {
                                        double tmpVal = lowVal;
                                        lowVal = hiVal;
                                        hiVal = tmpVal;
                                    }

                                    if ( isXBaseAxis )
                                    {

                                        double centerVal = valueHandler.BarCenterValue( curve, barWidth, iPt, xVal, iBar );

                                        if ( x < centerVal - barWidthUserHalf ||
                                                x > centerVal + barWidthUserHalf ||
                                                yAct < lowVal || yAct > hiVal )
                                            continue;
                                    }
                                    else
                                    {
                                        double centerVal = valueHandler.BarCenterValue( curve, barWidth, iPt, yVal, iBar );

                                        if ( yAct < centerVal - barWidthUserHalf ||
                                                yAct > centerVal + barWidthUserHalf ||
                                                x < lowVal || x > hiVal )
                                            continue;
                                    }

                                    if ( nearestBar == null )
                                    {
                                        iNearestBar = iPt;
                                        nearestBar = curve;
                                    }
                                }
                                else if ( xVal >= _xAxis._scale._min && xVal <= _xAxis._scale._max &&
                                            yVal >= yMinAct && yVal <= yMaxAct )
                                {
                                    if ( curve is LineItem && _lineType == LineType.Stack )
                                    {
                                        double zVal;
                                        valueHandler.GetValues( curve, iPt, out xVal, out zVal, out yVal );
                                    }

                                    distX = ( xVal - x ) * xPixPerUnit;
开发者ID:cliffton2008,项目名称:JNMAutoTrader_Capital,代码行数:67,代码来源:GraphPane.cs

示例3: CreateBarLabels

        /// <summary>
        /// Create a TextLabel for each bar in the GraphPane.
        /// Call this method only after calling AxisChange()
        /// </summary>
        /// <remarks>
        /// This method will go through the bars, create a label that corresponds to the bar value,
        /// and place it on the graph depending on user preferences.  This works for horizontal or
        /// vertical bars in clusters or stacks.</remarks>
        /// <param name="pane">The GraphPane in which to place the text labels.</param>
        /// <param name="isBarCenter">true to center the labels inside the bars, false to
        /// place the labels just above the top of the bar.</param>
        /// <param name="valueFormat">The double.ToString string format to use for creating
        /// the labels
        /// </param>
        private void CreateBarLabels( GraphPane pane, bool isBarCenter, string valueFormat )
        {
            bool isVertical = pane.BarSettings.Base == BarBase.X;

            // Make the gap between the bars and the labels = 2% of the axis range
            float labelOffset;
            if ( isVertical )
                labelOffset = (float) ( pane.YAxis.Scale.Max - pane.YAxis.Scale.Min ) * 0.02f;
            else
                labelOffset = (float) ( pane.XAxis.Scale.Max - pane.XAxis.Scale.Min ) * 0.02f;

            // keep a count of the number of BarItems
            int curveIndex = 0;

            // Get a valuehandler to do some calculations for us
            ValueHandler valueHandler = new ValueHandler( pane, true );

            // Loop through each curve in the list
            foreach ( CurveItem curve in pane.CurveList )
            {
                // work with BarItems only
                BarItem bar = curve as BarItem;
                if ( bar != null )
                {
                    IPointList points = curve.Points;

                    // Loop through each point in the BarItem
                    for ( int i=0; i<points.Count; i++ )
                    {
                        // Get the high, low and base values for the current bar
                        // note that this method will automatically calculate the "effective"
                        // values if the bar is stacked
                        double baseVal, lowVal, hiVal;
                        valueHandler.GetValues( curve, i, out baseVal, out lowVal, out hiVal );

                        // Get the value that corresponds to the center of the bar base
                        // This method figures out how the bars are positioned within a cluster
                        float centerVal = (float) valueHandler.BarCenterValue( bar,
                            bar.GetBarWidth( pane ), i, baseVal, curveIndex );

                        // Create a text label -- note that we have to go back to the original point
                        // data for this, since hiVal and lowVal could be "effective" values from a bar stack
                        string barLabelText	= ( isVertical ? points[i].Y : points[i].X ).ToString( valueFormat );

                        // Calculate the position of the label -- this is either the X or the Y coordinate
                        // depending on whether they are horizontal or vertical bars, respectively
                        float position;
                        if ( isBarCenter )
                            position = (float) (hiVal + lowVal) / 2.0f;
                        else
                            position = (float) hiVal + labelOffset;

                        // Create the new TextObj
                        TextObj label;
                        if ( isVertical )
                            label = new TextObj( barLabelText, centerVal, position );
                        else
                            label = new TextObj( barLabelText, position, centerVal );

                        // Configure the TextObj
                        label.Location.CoordinateFrame	= CoordType.AxisXYScale;
                        label.FontSpec.Size					= 12;
                        label.FontSpec.FontColor			= Color.Black;
                        label.FontSpec.Angle					= isVertical ? 90 : 0;
                        label.Location.AlignH				= isBarCenter ? AlignH.Center : AlignH.Left;
                        label.Location.AlignV				= AlignV.Center;
                        label.FontSpec.Border.IsVisible	= false;
                        label.FontSpec.Fill.IsVisible		= false;

                        // Add the TextObj to the GraphPane
                        pane.GraphObjList.Add( label );
                    }
                }
                curveIndex++;
            }
        }
开发者ID:Jungwon,项目名称:ZedGraph,代码行数:90,代码来源:HorizontalBarsWithLabels.cs

示例4: HorizontalBarDemo

        public HorizontalBarDemo()
            : base("A sideways bar demo.\n" +
								"This demo also shows how to add labels to the bars, in this " +
								"case showing the value of each bar",
								"HorizontalBar Demo", DemoType.Bar)
        {
            GraphPane myPane = base.GraphPane;

            // Set the title and axis labels
            myPane.Title.Text = "Horizontal Bar Graph";
            myPane.XAxis.Title.Text = "Performance Factor";
            myPane.YAxis.Title.Text = "Grouping";

            // Enter some random data values
            double[] y = { 100, 115, 75, -22, 98, 40, -10 };
            double[] y2 = { 90, 100, 95, -35, 80, 35, 35 };
            double[] y3 = { 80, 110, 65, -15, 54, 67, 18 };

            // Generate a bar with "Curve 1" in the legend
            BarItem myCurve = myPane.AddBar( "Curve 1", y, null, Color.Red );
            // Fill the bar with a red-white-red gradient
            myCurve.Bar.Fill = new Fill( Color.Red, Color.White, Color.Red, 90F );

            // Generate a bar with "Curve 2" in the legend
            myCurve = myPane.AddBar( "Curve 2", y2, null, Color.Blue );
            // Fill the bar with a blue-white-blue gradient for a 3d look
            myCurve.Bar.Fill = new Fill( Color.Blue, Color.White, Color.Blue, 90F );

            // Generate a bar with "Curve 3" in the legend
            myCurve = myPane.AddBar( "Curve 3", y3, null, Color.Green );
            // Fill the bar with a Green-white-Green gradient for a 3d look
            myCurve.Bar.Fill = new Fill( Color.White, Color.Green, 90F );

            // Draw the X tics between the labels instead of at the labels
            myPane.YAxis.MajorTic.IsBetweenLabels = true;

            // Set the XAxis to an ordinal type
            myPane.YAxis.Type = AxisType.Ordinal;
            // draw the X axis zero line
            myPane.XAxis.MajorGrid.IsZeroLine = true;

            //This is the part that makes the bars horizontal
            myPane.BarSettings.Base = BarBase.Y;

            // Fill the axis background with a color gradient
            myPane.Chart.Fill = new Fill( Color.White,
                Color.FromArgb( 255, 255, 166), 45.0F );

            base.ZedGraphControl.AxisChange();

            // The ValueHandler is a helper that does some position calculations for us.
            ValueHandler valueHandler = new ValueHandler( myPane, true );

            // Display a value for the maximum of each bar cluster
            // Shift the text items by 5 user scale units above the bars
            const float shift = 3;

            int ord = 0;
            foreach ( CurveItem curve in myPane.CurveList )
            {
                BarItem bar = curve as BarItem;

                if ( bar != null )
                {
                    IPointList points = curve.Points;

                    for ( int i=0; i<points.Count; i++ )
                    {
                        double xVal = points[i].X;
                        // Calculate the Y value at the center of each bar
                        double yVal = valueHandler.BarCenterValue( curve, curve.GetBarWidth( myPane ),
                                    i, points[i].Y, ord );

                        // format the label string to have 1 decimal place
                        string lab = xVal.ToString( "F0" );

                        // create the text item (assumes the x axis is ordinal or text)
                        // for negative bars, the label appears just above the zero value
                        TextObj text = new TextObj( lab, (float) xVal + ( xVal > 0 ? shift : -shift ),
                                                        (float) yVal );

                        // tell Zedgraph to use user scale units for locating the TextObj
                        text.Location.CoordinateFrame = CoordType.AxisXYScale;
                        text.FontSpec.Size = 10;
                        // AlignH the left-center of the text to the specified point
                        text.Location.AlignH =  xVal > 0 ? AlignH.Left : AlignH.Right;
                        text.Location.AlignV = AlignV.Center;
                        text.FontSpec.Border.IsVisible = false;
                        // rotate the text 90 degrees
                        text.FontSpec.Angle = 0;
                        text.FontSpec.Fill.IsVisible = false;
                        // add the TextObj to the list
                        myPane.GraphObjList.Add( text );
                    }
                }

                ord++;
            }
        }
开发者ID:Jungwon,项目名称:ZedGraph,代码行数:99,代码来源:HorizontalBarDemo.cs

示例5: Form1_Load


//.........这里部分代码省略.........
                double x = Math.Sin( i / 8.0 ) * 100000 + 100001;
                list.Add( x, y );
                //double z = Math.Abs( Math.Cos( i / 8.0 ) ) * y;
            }

            PointPairList list2 = new PointPairList( list );
            PointPairList list3 = new PointPairList( list );
            BarItem myCurve = myPane.AddBar( "curve 1", list, Color.Blue );
            BarItem myCurve2 = myPane.AddBar( "curve 2", list2, Color.Red );
            BarItem myCurve3 = myPane.AddBar( "curve 3", list3, Color.Green );

            //myPane.XAxis.IsSkipLastLabel = false;
            //myPane.XAxis.IsPreventLabelOverlap = false;
            //myPane.XAxis.ScaleFormat = "dd/MM HH:mm";
            //myPane.XAxis.Type = AxisType.Date;
            myPane.BarType = BarType.PercentStack;
            myPane.BarBase = BarBase.Y;
            myPane.AxisChange( this.CreateGraphics() );

            ValueHandler valueHandler = new ValueHandler(myPane, true);
            const float shift = 0;
            int iOrd = 0;
            foreach (CurveItem oCurveItem in myPane.CurveList)
            {
                BarItem oBarItem = oCurveItem as BarItem;
                if (oBarItem != null)
                {
                    PointPairList oPointPairList = oCurveItem.Points as PointPairList;
                    for (int i=0; i<oPointPairList.Count; i++)
                    {
                        double xVal = oPointPairList[i].X;
                        string sLabel = string.Concat(xVal.ToString("F0"), "%");

                        double yVal = valueHandler.BarCenterValue(oCurveItem, oCurveItem.GetBarWidth(myPane), i, oPointPairList[i].Y, iOrd);
                        double x1, x2, y;
                        valueHandler.GetValues( oCurveItem, i, out y, out x1, out x2 );

                        xVal = ( x1 + x2 ) / 2.0;

                        TextItem oTextItem = new TextItem(sLabel, (float) xVal + (xVal > 0 ? shift : -shift ), (float) yVal);
                        oTextItem.Location.CoordinateFrame = CoordType.AxisXYScale;
                        oTextItem.Location.AlignH =  AlignH.Center;
                        oTextItem.Location.AlignV = AlignV.Center;
                        oTextItem.FontSpec.Border.IsVisible = true;
                        oTextItem.FontSpec.Angle = 0;
                        oTextItem.FontSpec.Fill.IsVisible = false;
                        myPane.GraphItemList.Add(oTextItem);
                    }
                }

                iOrd++;
            }

            trackBar1.Minimum = 0;
            trackBar1.Maximum = 100;
            trackBar1.Value = 50;

            #endif

            #if false	// vertical bars with labels

            myPane = new GraphPane( new RectangleF( 0, 0, 640, 480 ), "Title", "XAxis", "YAxis" );

            PointPairList list = new PointPairList();
            PointPairList list2 = new PointPairList();
            PointPairList list3 = new PointPairList();
开发者ID:Jungwon,项目名称:ZedGraph,代码行数:67,代码来源:Form1.cs

示例6: CreateStackBarLabels

        // Call this method only after calling AxisChange()
        private void CreateStackBarLabels( GraphPane graphPane )
        {
            float labelOffset = (float)( 0.02 * ( graphPane.XAxis.Scale.Max - graphPane.XAxis.Scale.Min ) );
            ValueHandler valueHandler = new ValueHandler( graphPane, true );
            int barIndex = -1;

            foreach ( CurveItem curve in graphPane.CurveList )
            {
                if ( curve is BarItem )
                {
                    BarItem bar = curve as BarItem;
                    barIndex++;
                    float barWidth = bar.GetBarWidth( graphPane );

                    IPointList points = bar.Points;

                    for ( int i = 0; i < points.Count; i++ )
                    {
                        double labelYCoordinate = valueHandler.BarCenterValue( bar, barWidth, i, points[i].Y, barIndex );

                        double baseVal, lowVal, hiVal;

                        valueHandler.GetValues( bar, i, out baseVal, out lowVal, out hiVal );

                        float labelXCoordinate = (float)( lowVal + hiVal ) / 2.0f;

                        string barLabelText = ( points[i].X ).ToString( "N2" );

                        TextObj label = new TextObj( barLabelText, (float)labelXCoordinate, (float)labelYCoordinate );

                        label.Location.CoordinateFrame = CoordType.AxisXYScale;
                        label.FontSpec.Size = 10;
                        label.FontSpec.FontColor = Color.Black;
                        label.Location.AlignH = AlignH.Left;
                        label.Location.AlignV = AlignV.Center;
                        label.FontSpec.Border.IsVisible = false;
                        label.FontSpec.Fill.IsVisible = false;

                        graphPane.GraphObjList.Add( label );
                    }
                }
            }
        }
开发者ID:Jungwon,项目名称:ZedGraph,代码行数:44,代码来源:Form1.cs

示例7: CreateBarLabels

        // Call this method after calling AxisChange()
        private void CreateBarLabels( GraphPane pane )
        {
            // Make the gap between the bars and the labels = 2% of the axis range
            float labelOffset = (float)( pane.YAxis.Scale.Max - pane.YAxis.Scale.Min ) * 0.02f;

            foreach ( CurveItem curve in pane.CurveList )
            {
                BarItem bar = curve as BarItem;

                if ( bar != null )
                {
                    IPointList points = curve.Points;

                    for ( int i = 0; i < points.Count; i++ )
                    {
                        ValueHandler valueHandler		=
                            new ValueHandler( pane, true );

                        int curveIndex					=
                            pane.CurveList.IndexOf( curve );

                        double labelXCoordintate			=
                            valueHandler.BarCenterValue( bar,
                            bar.GetBarWidth( pane ), i, points[ i ].X,
                            curveIndex );

                        float labelYCoordinate				=
                            ( float ) points[ i ].Y + labelOffset;

                        string barLabelText				=
                            ( points[ i ].Y / 1000 ).ToString( "N2" );

                        TextObj label					=
                            new TextObj( barLabelText, ( float ) labelXCoordintate,
                            labelYCoordinate );

                        label.Location.CoordinateFrame	= CoordType.AxisXYScale;
                        label.FontSpec.Size				= 10;
                        label.FontSpec.FontColor		= Color.Black;
                        label.FontSpec.Angle = 90;
                        label.Location.AlignH			= AlignH.Left;
                        label.Location.AlignV			= AlignV.Center;
                        label.FontSpec.Border.IsVisible	= false;
                        label.FontSpec.Fill.IsVisible	= false;

                        pane.GraphObjList.Add( label );
                    }
                }
            }
        }
开发者ID:Jungwon,项目名称:ZedGraph,代码行数:51,代码来源:Form1.cs


注:本文中的ZedGraph.ValueHandler.BarCenterValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。