本文整理汇总了C#中ZedGraph.ValueHandler.GetValues方法的典型用法代码示例。如果您正苦于以下问题:C# ValueHandler.GetValues方法的具体用法?C# ValueHandler.GetValues怎么用?C# ValueHandler.GetValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZedGraph.ValueHandler
的用法示例。
在下文中一共展示了ValueHandler.GetValues方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawCurve
/// <summary>
/// Draw the this <see cref="CurveItem"/> to the specified <see cref="Graphics"/>
/// device. The format (stair-step or line) of the curve is
/// defined by the <see cref="StepType"/> property. The routine
/// only draws the line segments; the symbols are drawn by the
/// <see cref="Symbol.Draw"/> method. This method
/// is normally only called by the Draw method of the
/// <see cref="CurveItem"/> object
/// </summary>
/// <param name="g">
/// A graphic device object to be drawn into. This is normally e.Graphics from the
/// PaintEventArgs argument to the Paint() method.
/// </param>
/// <param name="scaleFactor">
/// The scaling factor to be used for rendering objects. This is calculated and
/// passed down by the parent <see cref="GraphPane"/> object using the
/// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
/// font sizes, etc. according to the actual size of the graph.
/// </param>
/// <param name="pane">
/// A reference to the <see cref="GraphPane"/> object that is the parent or
/// owner of this object.
/// </param>
/// <param name="curve">A <see cref="LineItem"/> representing this
/// curve.</param>
public void DrawCurve( Graphics g, GraphPane pane,
CurveItem curve, float scaleFactor )
{
Line source = this;
if ( curve.IsSelected )
source = Selection.Line;
float tmpX, tmpY,
lastX = float.MaxValue,
lastY = float.MaxValue;
double curX, curY, lowVal;
PointPair curPt, lastPt = new PointPair();
bool lastBad = true;
IPointList points = curve.Points;
ValueHandler valueHandler = new ValueHandler( pane, false );
Axis yAxis = curve.GetYAxis( pane );
Axis xAxis = curve.GetXAxis( pane );
bool xIsLog = xAxis._scale.IsLog;
bool yIsLog = yAxis._scale.IsLog;
float minX = pane.Chart.Rect.Left;
float maxX = pane.Chart.Rect.Right;
using ( Pen pen = source.GetPen( pane, scaleFactor ) )
{
if ( points != null && !_color.IsEmpty && this.IsVisible )
{
bool lastOut = false;
bool isOut;
// Loop over each point in the curve
for ( int i = 0; i < points.Count; i++ )
{
curPt = points[i];
if ( pane.LineType == LineType.Stack )
{
if ( !valueHandler.GetValues( curve, i, out curX, out lowVal, out curY ) )
{
curX = PointPair.Missing;
curY = PointPair.Missing;
}
}
else
{
curX = curPt.X;
curY = curPt.Y;
}
// Any value set to double max is invalid and should be skipped
// This is used for calculated values that are out of range, divide
// by zero, etc.
// Also, any value <= zero on a log scale is invalid
if ( curX == PointPair.Missing ||
curY == PointPair.Missing ||
System.Double.IsNaN( curX ) ||
System.Double.IsNaN( curY ) ||
System.Double.IsInfinity( curX ) ||
System.Double.IsInfinity( curY ) ||
( xIsLog && curX <= 0.0 ) ||
( yIsLog && curY <= 0.0 ) )
{
// If the point is invalid, then make a linebreak only if IsIgnoreMissing is false
// LastX and LastY are always the last valid point, so this works out
lastBad = lastBad || !pane.IsIgnoreMissing;
isOut = true;
}
else
{
// Transform the current point from user scale units to
// screen coordinates
tmpX = xAxis.Scale.Transform( curve.IsOverrideOrdinal, i, curX );
tmpY = yAxis.Scale.Transform( curve.IsOverrideOrdinal, i, curY );
isOut = (tmpX < minX || tmpX > maxX);
//.........这里部分代码省略.........
示例2: DrawSingleBar
/// <summary>
/// Protected internal routine that draws the specified single bar (an individual "point")
/// of this series to the specified <see cref="Graphics"/> device.
/// </summary>
/// <param name="g">
/// A graphic device object to be drawn into. This is normally e.Graphics from the
/// PaintEventArgs argument to the Paint() method.
/// </param>
/// <param name="pane">
/// A reference to the <see cref="GraphPane"/> object that is the parent or
/// owner of this object.
/// </param>
/// <param name="curve">A <see cref="CurveItem"/> object representing the
/// <see cref="Bar"/>'s to be drawn.</param>
/// <param name="index">
/// The zero-based index number for the single bar to be drawn.
/// </param>
/// <param name="pos">
/// The ordinal position of the this bar series (0=first bar, 1=second bar, etc.)
/// in the cluster of bars.
/// </param>
/// <param name="baseAxis">The <see cref="Axis"/> class instance that defines the base (independent)
/// axis for the <see cref="Bar"/></param>
/// <param name="valueAxis">The <see cref="Axis"/> class instance that defines the value (dependent)
/// axis for the <see cref="Bar"/></param>
/// <param name="barWidth">
/// The width of each bar, in pixels.
/// </param>
/// <param name="scaleFactor">
/// The scaling factor to be used for rendering objects. This is calculated and
/// passed down by the parent <see cref="GraphPane"/> object using the
/// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
/// font sizes, etc. according to the actual size of the graph.
/// </param>
protected virtual void DrawSingleBar(Graphics g, GraphPane pane,
CurveItem curve,
int index, int pos, Axis baseAxis, Axis valueAxis,
float barWidth, float scaleFactor)
{
// pixBase = pixel value for the bar center on the base axis
// pixHiVal = pixel value for the bar top on the value axis
// pixLowVal = pixel value for the bar bottom on the value axis
float pixBase, pixHiVal, pixLowVal;
float clusterWidth = pane.BarSettings.GetClusterWidth();
//float barWidth = curve.GetBarWidth( pane );
float clusterGap = pane._barSettings.MinClusterGap*barWidth;
float barGap = barWidth*pane._barSettings.MinBarGap;
// curBase = the scale value on the base axis of the current bar
// curHiVal = the scale value on the value axis of the current bar
// curLowVal = the scale value of the bottom of the bar
double curBase, curLowVal, curHiVal;
var valueHandler = new ValueHandler(pane, false);
valueHandler.GetValues(curve, index, out curBase, out curLowVal, out curHiVal);
// Any value set to double max is invalid and should be skipped
// This is used for calculated values that are out of range, divide
// by zero, etc.
// Also, any value <= zero on a log scale is invalid
if (!curve.Points[index].IsInvalid)
{
// calculate a pixel value for the top of the bar on value axis
pixLowVal = valueAxis.Scale.Transform(curve.IsOverrideOrdinal, index, curLowVal);
pixHiVal = valueAxis.Scale.Transform(curve.IsOverrideOrdinal, index, curHiVal);
// calculate a pixel value for the center of the bar on the base axis
pixBase = baseAxis.Scale.Transform(curve.IsOverrideOrdinal, index, curBase);
// Calculate the pixel location for the side of the bar (on the base axis)
float pixSide = pixBase - clusterWidth/2.0F + clusterGap/2.0F +
pos*(barWidth + barGap);
// Draw the bar
if (pane._barSettings.Base == BarBase.X)
Draw(g, pane, pixSide, pixSide + barWidth, pixLowVal,
pixHiVal, scaleFactor, true,
curve.Points[index]);
else
Draw(g, pane, pixLowVal, pixHiVal, pixSide, pixSide + barWidth,
scaleFactor, true,
curve.Points[index]);
}
}
示例3: BuildLowPointsArray
/// <summary>
/// Build an array of <see cref="PointF"/> values (pixel coordinates) that represents
/// the low values for the current curve.
/// </summary>
/// <remarks>Note that this drawing routine ignores <see cref="PointPairBase.Missing"/>
/// values, but it does not "break" the line to indicate values are missing.
/// </remarks>
/// <param name="pane">A reference to the <see cref="GraphPane"/> object that is the parent or
/// owner of this object.</param>
/// <param name="curve">A <see cref="LineItem"/> representing this
/// curve.</param>
/// <param name="arrPoints">An array of <see cref="PointF"/> values in pixel
/// coordinates representing the current curve.</param>
/// <param name="count">The number of points contained in the "arrPoints"
/// parameter.</param>
/// <returns>true for a successful points array build, false for data problems</returns>
public bool BuildLowPointsArray( GraphPane pane, CurveItem curve,
out PointF[] arrPoints, out int count )
{
arrPoints = null;
count = 0;
IPointList points = curve.Points;
if ( this.IsVisible && !this.Color.IsEmpty && points != null )
{
int index = 0;
float curX, curY,
lastX = 0,
lastY = 0;
double x, y, hiVal;
ValueHandler valueHandler = new ValueHandler( pane, false );
// Step type plots get twice as many points. Always add three points so there is
// room to close out the curve for area fills.
arrPoints = new PointF[( _stepType == ZedGraph.StepType.NonStep ? 1 : 2 ) *
( pane.LineType == LineType.Stack ? 2 : 1 ) *
points.Count + 1];
// Loop backwards over all points in the curve
// In this case an array of points was already built forward by BuildPointsArray().
// This time we build backwards to complete a loop around the area between two curves.
for ( int i = points.Count - 1; i >= 0; i-- )
{
// Make sure the current point is valid
if ( !points[i].IsInvalid )
{
// Get the user scale values for the current point
valueHandler.GetValues( curve, i, out x, out y, out hiVal );
if ( x == PointPair.Missing || y == PointPair.Missing )
continue;
// Transform the user scale values to pixel locations
Axis xAxis = curve.GetXAxis( pane );
curX = xAxis.Scale.Transform( curve.IsOverrideOrdinal, i, x );
Axis yAxis = curve.GetYAxis( pane );
curY = yAxis.Scale.Transform( curve.IsOverrideOrdinal, i, y );
// Add the pixel value pair into the points array
// Two points are added for step type curves
// ignore step-type setting for smooth curves
if ( _isSmooth || index == 0 || this.StepType == StepType.NonStep )
{
arrPoints[index].X = curX;
arrPoints[index].Y = curY;
}
else if ( this.StepType == StepType.ForwardStep )
{
arrPoints[index].X = curX;
arrPoints[index].Y = lastY;
index++;
arrPoints[index].X = curX;
arrPoints[index].Y = curY;
}
else if ( this.StepType == StepType.RearwardStep )
{
arrPoints[index].X = lastX;
arrPoints[index].Y = curY;
index++;
arrPoints[index].X = curX;
arrPoints[index].Y = curY;
}
lastX = curX;
lastY = curY;
index++;
}
}
// Make sure there is at least one valid point
if ( index == 0 )
return false;
// Add an extra point at the end, since the smoothing algorithm requires it
arrPoints[index] = arrPoints[index - 1];
index++;
count = index;
//.........这里部分代码省略.........
示例4: BuildPointsArray
/// <summary>
/// Build an array of <see cref="PointF"/> values (pixel coordinates) that represents
/// the current curve. Note that this drawing routine ignores <see cref="PointPairBase.Missing"/>
/// values, but it does not "break" the line to indicate values are missing.
/// </summary>
/// <param name="pane">A reference to the <see cref="GraphPane"/> object that is the parent or
/// owner of this object.</param>
/// <param name="curve">A <see cref="LineItem"/> representing this
/// curve.</param>
/// <param name="arrPoints">An array of <see cref="PointF"/> values in pixel
/// coordinates representing the current curve.</param>
/// <param name="count">The number of points contained in the "arrPoints"
/// parameter.</param>
/// <returns>true for a successful points array build, false for data problems</returns>
public bool BuildPointsArray( GraphPane pane, CurveItem curve,
out PointF[] arrPoints, out int count )
{
arrPoints = null;
count = 0;
IPointList points = curve.Points;
if ( this.IsVisible && !this.Color.IsEmpty && points != null )
{
int index = 0;
float curX, curY,
lastX = 0,
lastY = 0;
double x, y, lowVal;
ValueHandler valueHandler = new ValueHandler( pane, false );
// Step type plots get twice as many points. Always add three points so there is
// room to close out the curve for area fills.
arrPoints = new PointF[( _stepType == ZedGraph.StepType.NonStep ? 1 : 2 ) *
points.Count + 1];
// Loop over all points in the curve
for ( int i = 0; i < points.Count; i++ )
{
// make sure that the current point is valid
if ( !points[i].IsInvalid )
{
// Get the user scale values for the current point
// use the valueHandler only for stacked types
if ( pane.LineType == LineType.Stack )
{
valueHandler.GetValues( curve, i, out x, out lowVal, out y );
}
// otherwise, just access the values directly. Avoiding the valueHandler for
// non-stacked types is an optimization to minimize overhead in case there are
// a large number of points.
else
{
x = points[i].X;
y = points[i].Y;
}
if ( x == PointPair.Missing || y == PointPair.Missing )
continue;
// Transform the user scale values to pixel locations
Axis xAxis = curve.GetXAxis( pane );
curX = xAxis.Scale.Transform( curve.IsOverrideOrdinal, i, x );
Axis yAxis = curve.GetYAxis( pane );
curY = yAxis.Scale.Transform( curve.IsOverrideOrdinal, i, y );
if ( curX < -1000000 || curY < -1000000 || curX > 1000000 || curY > 1000000 )
continue;
// Add the pixel value pair into the points array
// Two points are added for step type curves
// ignore step-type setting for smooth curves
if ( _isSmooth || index == 0 || this.StepType == StepType.NonStep )
{
arrPoints[index].X = curX;
arrPoints[index].Y = curY;
}
else if ( this.StepType == StepType.ForwardStep )
{
arrPoints[index].X = curX;
arrPoints[index].Y = lastY;
index++;
arrPoints[index].X = curX;
arrPoints[index].Y = curY;
}
else if ( this.StepType == StepType.RearwardStep )
{
arrPoints[index].X = lastX;
arrPoints[index].Y = curY;
index++;
arrPoints[index].X = curX;
arrPoints[index].Y = curY;
}
lastX = curX;
lastY = curY;
index++;
}
}
//.........这里部分代码省略.........
示例5: GetCoords
/// <summary>
/// Determine the coords for the rectangle associated with a specified point for
/// this <see cref="CurveItem" />
/// </summary>
/// <param name="pane">The <see cref="GraphPane" /> to which this curve belongs</param>
/// <param name="i">The index of the point of interest</param>
/// <param name="coords">A list of coordinates that represents the "rect" for
/// this point (used in an html AREA tag)</param>
/// <returns>true if it's a valid point, false otherwise</returns>
public override bool GetCoords(GraphPane pane, int i, out string coords)
{
coords = string.Empty;
if (i < 0 || i >= _points.Count)
return false;
Axis valueAxis = ValueAxis(pane);
Axis baseAxis = BaseAxis(pane);
// pixBase = pixel value for the bar center on the base axis
// pixHiVal = pixel value for the bar top on the value axis
// pixLowVal = pixel value for the bar bottom on the value axis
float pixBase, pixHiVal, pixLowVal;
float clusterWidth = pane.BarSettings.GetClusterWidth();
float barWidth = GetBarWidth(pane);
float clusterGap = pane._barSettings.MinClusterGap*barWidth;
float barGap = barWidth*pane._barSettings.MinBarGap;
// curBase = the scale value on the base axis of the current bar
// curHiVal = the scale value on the value axis of the current bar
// curLowVal = the scale value of the bottom of the bar
double curBase, curLowVal, curHiVal;
ValueHandler valueHandler = new ValueHandler(pane, false);
valueHandler.GetValues(this, i, out curBase, out curLowVal, out curHiVal);
// Any value set to double max is invalid and should be skipped
// This is used for calculated values that are out of range, divide
// by zero, etc.
// Also, any value <= zero on a log scale is invalid
if (!_points[i].IsInvalid3D) {
// calculate a pixel value for the top of the bar on value axis
pixLowVal = valueAxis.Scale.Transform(_isOverrideOrdinal, i, curLowVal);
pixHiVal = valueAxis.Scale.Transform(_isOverrideOrdinal, i, curHiVal);
// calculate a pixel value for the center of the bar on the base axis
pixBase = baseAxis.Scale.Transform(_isOverrideOrdinal, i, curBase);
// Calculate the pixel location for the side of the bar (on the base axis)
float pixSide = pixBase - clusterWidth/2.0F + clusterGap/2.0F +
pane.CurveList.GetBarItemPos(pane, this)*(barWidth + barGap);
// Draw the bar
if (baseAxis is XAxis || baseAxis is X2Axis)
coords = string.Format("{0:f0},{1:f0},{2:f0},{3:f0}",
pixSide, pixLowVal,
pixSide + barWidth, pixHiVal);
else
coords = string.Format("{0:f0},{1:f0},{2:f0},{3:f0}",
pixLowVal, pixSide,
pixHiVal, pixSide + barWidth);
return true;
}
return false;
}
示例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 );
}
}
}
}
示例7: DrawCurve
/// <summary>
/// Draw the this <see cref="CurveItem"/> to the specified <see cref="Graphics"/>
/// device. The format (stair-step or line) of the curve is
/// defined by the <see cref="StepType"/> property. The routine
/// only draws the line segments; the symbols are drawn by the
/// <see cref="Symbol.Draw"/> method. This method
/// is normally only called by the Draw method of the
/// <see cref="CurveItem"/> object
/// </summary>
/// <param name="g">
/// A graphic device object to be drawn into. This is normally e.Graphics from the
/// PaintEventArgs argument to the Paint() method.
/// </param>
/// <param name="scaleFactor">
/// The scaling factor to be used for rendering objects. This is calculated and
/// passed down by the parent <see cref="GraphPane"/> object using the
/// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
/// font sizes, etc. according to the actual size of the graph.
/// </param>
/// <param name="pane">
/// A reference to the <see cref="GraphPane"/> object that is the parent or
/// owner of this object.
/// </param>
/// <param name="curve">A <see cref="LineItem"/> representing this
/// curve.</param>
public void DrawCurve( Graphics g, GraphPane pane,
CurveItem curve, float scaleFactor)
{
Line source = this;
if ( curve.IsSelected )
source = Selection.Line;
// switch to int to optimize drawing speed (per Dale-a-b)
int tmpX, tmpY,
lastX = int.MaxValue,
lastY = int.MaxValue;
double curX, curY, lowVal;
PointPair curPt, lastPt = new PointPair();
bool lastBad = true;
IPointList points = curve.Points;
ValueHandler valueHandler = new ValueHandler( pane, false );
Axis yAxis = curve.GetYAxis( pane );
Axis xAxis = curve.GetXAxis( pane );
bool xIsLog = xAxis._scale.IsLog;
bool yIsLog = yAxis._scale.IsLog;
// switch to int to optimize drawing speed (per Dale-a-b)
int minX = (int)pane.Chart.Rect.Left;
int maxX = (int)pane.Chart.Rect.Right;
int minY = (int)pane.Chart.Rect.Top;
int maxY = (int)pane.Chart.Rect.Bottom;
using ( Pen pen = source.GetPen( pane, scaleFactor ) )
{
if ( points != null && !_color.IsEmpty && this.IsVisible )
{
//bool lastOut = false;
bool isOut;
bool isOptDraw = _isOptimizedDraw && points.Count > 1000;
// (Dale-a-b) we'll set an element to true when it has been drawn
bool[,] isPixelDrawn = null;
if ( isOptDraw )
isPixelDrawn = new bool[maxX + 1, maxY + 1];
// Loop over each point in the curve
for ( int i = 0; i < points.Count; i++ )
{
curPt = points[i];
if ( pane.LineType == LineType.Stack )
{
if ( !valueHandler.GetValues( curve, i, out curX, out lowVal, out curY ) )
{
curX = PointPair.Missing;
curY = PointPair.Missing;
}
}
else
{
curX = curPt.X;
curY = curPt.Y;
}
// Any value set to double max is invalid and should be skipped
// This is used for calculated values that are out of range, divide
// by zero, etc.
// Also, any value <= zero on a log scale is invalid
if ( curX == PointPair.Missing ||
curY == PointPair.Missing ||
System.Double.IsNaN( curX ) ||
System.Double.IsNaN( curY ) ||
System.Double.IsInfinity( curX ) ||
System.Double.IsInfinity( curY ) ||
( xIsLog && curX <= 0.0 ) ||
( yIsLog && curY <= 0.0 ) )
//.........这里部分代码省略.........
示例8: Draw
/// <summary>
/// Draw all the <see cref="ErrorBar"/>'s to the specified <see cref="Graphics"/>
/// device as a an error bar at each defined point.
/// </summary>
/// <param name="g">
/// A graphic device object to be drawn into. This is normally e.Graphics from the
/// PaintEventArgs argument to the Paint() method.
/// </param>
/// <param name="pane">
/// A reference to the <see cref="GraphPane"/> object that is the parent or
/// owner of this object.
/// </param>
/// <param name="curve">A <see cref="CurveItem"/> object representing the
/// <see cref="Bar"/>'s to be drawn.</param>
/// <param name="baseAxis">The <see cref="Axis"/> class instance that defines the base (independent)
/// axis for the <see cref="Bar"/></param>
/// <param name="valueAxis">The <see cref="Axis"/> class instance that defines the value (dependent)
/// axis for the <see cref="Bar"/></param>
/// <param name="scaleFactor">
/// The scaling factor to be used for rendering objects. This is calculated and
/// passed down by the parent <see cref="GraphPane"/> object using the
/// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
/// font sizes, etc. according to the actual size of the graph.
/// </param>
public void Draw( Graphics g, GraphPane pane, ErrorBarItem curve,
Axis baseAxis, Axis valueAxis, float scaleFactor )
{
ValueHandler valueHandler = new ValueHandler( pane, false );
float pixBase, pixValue, pixLowValue;
double scaleBase, scaleValue, scaleLowValue;
if ( curve.Points != null && this.IsVisible )
{
using ( Pen pen = !curve.IsSelected ? new Pen( _color, _penWidth ) :
new Pen( Selection.Border.Color, Selection.Border.Width ) )
{
// Loop over each defined point
for ( int i = 0; i < curve.Points.Count; i++ )
{
valueHandler.GetValues( curve, i, out scaleBase,
out scaleLowValue, out scaleValue );
// Any value set to double max is invalid and should be skipped
// This is used for calculated values that are out of range, divide
// by zero, etc.
// Also, any value <= zero on a log scale is invalid
if ( !curve.Points[i].IsInvalid3D &&
( scaleBase > 0 || !baseAxis._scale.IsLog ) &&
( ( scaleValue > 0 && scaleLowValue > 0 ) || !valueAxis._scale.IsLog ) )
{
pixBase = baseAxis.Scale.Transform( curve.IsOverrideOrdinal, i, scaleBase );
pixValue = valueAxis.Scale.Transform( curve.IsOverrideOrdinal, i, scaleValue );
pixLowValue = valueAxis.Scale.Transform( curve.IsOverrideOrdinal, i, scaleLowValue );
//if ( this.fill.IsGradientValueType )
// brush = fill.MakeBrush( _rect, _points[i] );
this.Draw( g, pane, baseAxis is XAxis || baseAxis is X2Axis, pixBase, pixValue,
pixLowValue, scaleFactor, pen, curve.IsSelected,
curve.Points[i] );
}
}
}
}
}
示例9: DrawSingleBar
protected override void DrawSingleBar(Graphics g, GraphPane pane, CurveItem curve,
int index, int pos, Axis baseAxis, Axis valueAxis, float barWidth, float scaleFactor)
{
base.DrawSingleBar(g, pane, curve, index, pos, baseAxis, valueAxis, barWidth, scaleFactor);
PointPair pointPair = curve.Points[index];
ErrorTag errorTag = pointPair.Tag as ErrorTag;
if (pointPair.IsInvalid || errorTag == null)
{
return;
}
double curBase, curLowVal, curHiVal;
ValueHandler valueHandler = new ValueHandler(pane, false);
valueHandler.GetValues(curve, index, out curBase, out curLowVal, out curHiVal);
float pixBase = baseAxis.Scale.Transform(curve.IsOverrideOrdinal, index, curBase);
double lowError = curHiVal - errorTag.Error;
float pixLowError = valueAxis.Scale.Transform(lowError);
float pixHiError = valueAxis.Scale.Transform(lowError + errorTag.Error*2);
float clusterWidth = pane.BarSettings.GetClusterWidth();
//float barWidth = curve.GetBarWidth( pane );
float clusterGap = pane.BarSettings.MinClusterGap * barWidth;
float barGap = barWidth * pane.BarSettings.MinBarGap;
// Calculate the pixel location for the side of the bar (on the base axis)
float pixSide = pixBase - clusterWidth / 2.0F + clusterGap / 2.0F +
pos * (barWidth + barGap);
// Draw the bar
if (pane.BarSettings.Base == BarBase.X)
{
if (barWidth >= 3 && errorTag.Error > 0)
{
// Draw whiskers
float pixMidX = (float)Math.Round(pixSide + barWidth / 2);
// Line
g.DrawLine(ErrorPen, pixMidX, pixHiError, pixMidX, pixLowError);
if (barWidth >= PIX_TERM_WIDTH)
{
// Ends
float pixLeft = pixMidX - (float) Math.Round(PIX_TERM_WIDTH/2);
float pixRight = pixLeft + PIX_TERM_WIDTH - 1;
g.DrawLine(ErrorPen, pixLeft, pixHiError, pixRight, pixHiError);
g.DrawLine(ErrorPen, pixLeft, pixLowError, pixRight, pixLowError);
}
}
}
else
{
if (barWidth >= 3 && errorTag.Error > 0)
{
// Draw whiskers
float pixMidY = (float)Math.Round(pixSide + barWidth / 2) + 1;
// Line
g.DrawLine(ErrorPen, pixLowError, pixMidY, pixHiError, pixMidY);
if (barWidth >= PIX_TERM_WIDTH)
{
// Ends
float pixTop = pixMidY - (float) Math.Round(PIX_TERM_WIDTH/2);
float pixBottom = pixTop + PIX_TERM_WIDTH - 1;
g.DrawLine(ErrorPen, pixHiError, pixTop, pixHiError, pixBottom);
g.DrawLine(ErrorPen, pixLowError, pixTop, pixLowError, pixBottom);
}
}
}
}
示例10: DrawSingleBar
/// <summary>
/// Protected internal routine that draws the specified single bar (an individual "point")
/// of this series to the specified <see cref="Graphics"/> device.
/// </summary>
/// <param name="g">
/// A graphic device object to be drawn into. This is normally e.Graphics from the
/// PaintEventArgs argument to the Paint() method.
/// </param>
/// <param name="pane">
/// A reference to the <see cref="GraphPane"/> object that is the parent or
/// owner of this object.
/// </param>
/// <param name="curve">A <see cref="CurveItem"/> object representing the
/// <see cref="Bar"/>'s to be drawn.</param>
/// <param name="index">
/// The zero-based index number for the single bar to be drawn.
/// </param>
/// <param name="pos">
/// The ordinal position of the this bar series (0=first bar, 1=second bar, etc.)
/// in the cluster of bars.
/// </param>
/// <param name="baseAxis">The <see cref="Axis"/> class instance that defines the base (independent)
/// axis for the <see cref="Bar"/></param>
/// <param name="valueAxis">The <see cref="Axis"/> class instance that defines the value (dependent)
/// axis for the <see cref="Bar"/></param>
/// <param name="barWidth">
/// The width of each bar, in pixels.
/// </param>
/// <param name="scaleFactor">
/// The scaling factor to be used for rendering objects. This is calculated and
/// passed down by the parent <see cref="GraphPane"/> object using the
/// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
/// font sizes, etc. according to the actual size of the graph.
/// </param>
protected override void DrawSingleBar(Graphics g, GraphPane pane,
CurveItem curve,
int index, int pos, Axis baseAxis, Axis valueAxis,
float barWidth, float scaleFactor)
{
//float scaledSize = GetBarWidth( pane, baseAxis, scaleFactor );
// pixBase = pixel value for the bar center on the base axis
// pixValue = pixel value for the bar top on the value axis
// pixLow = pixel value for the bar bottom on the value axis
float pixBase, pixHiVal, pixLowVal;
// curBase = the scale value on the base axis of the current bar
// curValue = the scale value on the value axis of the current bar
double curBase, curLowVal, curHiVal;
var valueHandler = new ValueHandler(pane, false);
valueHandler.GetValues(curve, index, out curBase,
out curLowVal, out curHiVal);
barWidth = GetBarWidth(pane, baseAxis, scaleFactor);
// curLow = the scale value on the value axis for the bottom of the current bar
// Get a "low" value for the bottom of the bar and verify validity
if (curLowVal == PointPair.Missing ||
Double.IsNaN(curLowVal) ||
Double.IsInfinity(curLowVal))
curLowVal = 0;
// Any value set to double max is invalid and should be skipped
// This is used for calculated values that are out of range, divide
// by zero, etc.
// Also, any value <= zero on a log scale is invalid
if (!curve.Points[index].IsInvalid)
{
// calculate a pixel value for the top of the bar on value axis
pixHiVal = valueAxis.Scale.Transform(curve.IsOverrideOrdinal, index, curHiVal);
// calculate a pixel value for the center of the bar on the base axis
pixBase = baseAxis.Scale.Transform(curve.IsOverrideOrdinal, index, curBase);
pixLowVal = valueAxis.Scale.Transform(curve.IsOverrideOrdinal, index, curLowVal);
// Calculate the pixel location for the side of the bar (on the base axis)
float pixSide = pixBase - barWidth/2.0F;
// Draw the bar
if (baseAxis is XAxis)
Draw(g, pane, pixSide, pixSide + barWidth, pixLowVal,
pixHiVal, scaleFactor, true,
curve.Points[index]);
else
Draw(g, pane, pixLowVal, pixHiVal, pixSide, pixSide + barWidth,
scaleFactor, true,
curve.Points[index]);
}
}
示例11: GetPoints
private IPointList GetPoints(CurveItem curve, GraphPane pane)
{
IPointList points = curve.Points;
ValueHandler valueHandler = new ValueHandler( pane, false );
if (pane.LineType == LineType.Stack)
{
// Loop over each point in the curve
for (int i = 0; i < points.Count; i++)
{
double x, y, unused;
if (!valueHandler.GetValues(curve, i, out x, out unused, out y))
{
x = PointPair.Missing;
y = PointPair.Missing;
}
points[i].X = x;
points[i].Y = y;
}
}
return points;
}
示例12: 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++;
}
}
示例13: Form1_Load
//.........这里部分代码省略.........
//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();
Random rand = new Random();
示例14: GetCoords
/// <summary>
/// Determine the coords for the rectangle associated with a specified point for
/// this <see cref="CurveItem" />
/// </summary>
/// <param name="pane">The <see cref="GraphPane" /> to which this curve belongs</param>
/// <param name="i">The index of the point of interest</param>
/// <param name="coords">A list of coordinates that represents the "rect" for
/// this point (used in an html AREA tag)</param>
/// <returns>true if it's a valid point, false otherwise</returns>
public override bool GetCoords(GraphPane pane, int i, out string coords)
{
coords = string.Empty;
if (i < 0 || i >= _points.Count)
return false;
PointPair pt = _points[i];
if (pt.IsInvalid)
return false;
double x, y, z;
ValueHandler valueHandler = new ValueHandler(pane, false);
valueHandler.GetValues(this, i, out x, out z, out y);
Axis yAxis = GetYAxis(pane);
Axis xAxis = GetXAxis(pane);
PointF pixPt = new PointF(xAxis.Scale.Transform(_isOverrideOrdinal, i, x),
yAxis.Scale.Transform(_isOverrideOrdinal, i, y));
if (!pane.Chart.Rect.Contains(pixPt))
return false;
float halfSize = _symbol.Size*pane.CalcScaleFactor();
coords = string.Format("{0:f0},{1:f0},{2:f0},{3:f0}",
pixPt.X - halfSize, pixPt.Y - halfSize,
pixPt.X + halfSize, pixPt.Y + halfSize);
return true;
}
示例15: HandlePointValues
private Point HandlePointValues( Point mousePt )
{
int iPt;
GraphPane pane;
object nearestObj;
using ( Graphics g = this.CreateGraphics() )
{
if ( _masterPane.FindNearestPaneObject( mousePt,
g, out pane, out nearestObj, out iPt ) )
{
if ( nearestObj is CurveItem && iPt >= 0 )
{
CurveItem curve = (CurveItem)nearestObj;
// Provide Callback for User to customize the tooltips
if ( this.PointValueEvent != null )
{
string label = this.PointValueEvent( this, pane, curve, iPt );
if ( label != null && label.Length > 0 )
{
this.SetToolTip(label, mousePt);
this.EnableToolTip();
}
else
this.DisableToolTip();
}
else
{
if ( curve is PieItem )
{
this.SetToolTip(((PieItem)curve).Value.ToString(this._pointValueFormat), mousePt);
}
else
{
PointPair pt = curve.Points[iPt];
if ( pt.Tag is string )
this.SetToolTip((string)pt.Tag, mousePt);
else
{
double xVal, yVal, lowVal;
ValueHandler valueHandler = new ValueHandler( pane, false );
if ( ( curve is BarItem || curve is ErrorBarItem || curve is HiLowBarItem )
&& pane.BarSettings.Base != BarBase.X )
valueHandler.GetValues( curve, iPt, out yVal, out lowVal, out xVal );
else
valueHandler.GetValues( curve, iPt, out xVal, out lowVal, out yVal );
string xStr = MakeValueLabel( curve.GetXAxis( pane ), xVal, iPt,
curve.IsOverrideOrdinal );
string yStr = MakeValueLabel( curve.GetYAxis( pane ), yVal, iPt,
curve.IsOverrideOrdinal );
this.SetToolTip("( " + xStr + ", " + yStr + " )", mousePt);
}
}
this.EnableToolTip();
}
}
else
this.DisableToolTip();
}
else
this.DisableToolTip();
}
return mousePt;
}