internal override void Draw(ChartGraphics g, int[] xValues, int[] stackValues, int lastPlotType) { g.Pen = new Pen(color, lineWidth); g.Color = color; double[] values = source.Values; int ax = 0, ay = 0; int nx = 0, ny = 0; for (int i = 0; i < xValues.Length; i++) { nx = xValues[i]; ny = g.GetY(values[i]); if (stacked && ny != Int32.MinValue) { ny += stackValues[i]; } if (visible && ny != Double.NaN && nx != 0 && ay != Int32.MinValue && ny != Int32.MinValue) { g.DrawLine(ax, ay, nx, ny); } stackValues[i] = ny; ax = nx; ay = ny; } //g.Pen = new Pen(); }
internal override void Draw(ChartGraphics g, int[] xValues, int[] stackValues, int lastPlotType) { g.Pen = new Pen(color, lineWidth); g.Color = color; double [] values = source.Values; int ax = 0, ay = 0, py; int nx = 0, ny = 0; for (int i = 0; i < xValues.Length; i++) { py = 0; nx = xValues[i]; ny = g.GetY(values[i]); if (!Double.IsNaN(values[i])) { if (stacked) { py = stackValues[i]; ny += (stackValues[i] == Int32.MinValue ? Int32.MinValue : stackValues[i]); } if (visible) { if (nx > ax + 1) // More than one pixel hop, draw intermediate pixels too { // For each pixel between nx and ax, calculate the y, plot the line int co = (ny - ay) / (nx - ax); int j = (ax > 0 ? ax : 1); // Skip 0 for (j = ax; j <= nx; j++) { if (ay != Int32.MinValue && ny != Int32.MinValue) { g.DrawLine(j, py, j, (co * (j - ax) + ay)); } } } else if (nx != 0 && py != Int32.MinValue && ny != Int32.MinValue) { g.DrawLine(nx, py, nx, ny); } } } // Special case with NaN doubles stackValues[i] = ny; ax = nx; ay = ny; } }
internal override void Draw(ChartGraphics g, int[] xValues, int[] stackValues, int lastPlotType) { g.Pen = new Pen(color, lineWidth); g.Color = color; int ax, ay, nx, ny; // Get X positions if (xVal1 == Int64.MinValue) { ax = g.MinX; } else if (xVal1 == Int64.MaxValue) { ax = g.MaxX; } else { ax = g.GetX(xVal1); } if (xVal2 == Int64.MinValue) { nx = g.MinX; } else if (xVal2 == Int64.MaxValue) { nx = g.MaxX; } else { nx = g.GetX(xVal2); } // Get Y positions if (yVal1 == Double.MinValue) { ay = g.MinY; } else if (yVal1 == Double.MaxValue) { ay = g.MaxY; } else { ay = g.GetY(yVal1); } if (yVal2 == Double.MinValue) { ny = g.MinY; } else if (yVal2 == Double.MaxValue) { ny = g.MaxY; } else { ny = g.GetY(yVal2); } // Draw the area if (visible) { if (ny > ay) { g.FillRect(ax, ay, nx, ny); } else { g.FillRect(ax, ny, nx, ay); } } // Set the stackvalues // Always use the y value of the second specified point to stack on if (yVal2 != Double.MaxValue) { for (int i = 0; i < stackValues.Length; i++) { if (xValues[i] < ax || xValues[i] > nx) { stackValues[i] = 0; } else { stackValues[i] = ny; } } } }
internal override void Draw(ChartGraphics g, int[] xValues, int[] stackValues, int lastPlotType) { g.Color = color; g.Pen = new Pen(color, lineWidth); int ax, ay, nx, ny; // Get X positions if (xVal1 == Int64.MinValue) { ax = g.MinX; } else if (xVal1 == Int64.MaxValue) { ax = g.MaxX; } else { ax = g.GetX(xVal1); } if (xVal2 == Int64.MinValue) { nx = g.MinX; } else if (xVal2 == Int64.MaxValue) { nx = g.MaxX; } else { nx = g.GetX(xVal2); } // Get Y positions if (yVal1 == Double.MinValue) { ay = g.MinY; } else if (yVal1 == Double.MaxValue) { ay = g.MaxY; } else { ay = g.GetY(yVal1); } if (yVal2 == Double.MinValue) { ny = g.MinY; } else if (yVal2 == Double.MaxValue) { ny = g.MaxY; } else { ny = g.GetY(yVal2); } // Draw the line if (visible) { g.DrawLine(ax, ay, nx, ny); } // Set the stackvalues int rx = nx - ax; if (rx != 0) { double rc = ((ny - ay) * 1.0d) / rx; for (int i = 0; i < xValues.Length; i++) { if (xValues[i] < ax || xValues[i] > nx) { stackValues[i] = 0; } else if (ay == ny) { stackValues[i] = ay; } else { stackValues[i] = (int)(rc * (xValues[i] - ax) + ay); } } } //g.Pen = ( new Pen( ); }
private void PlotChartGrid(ChartGraphics chartGraph) { Graphics g = chartGraph.Graphics; Font ft = normal_font; //defaultPen.Color = Color.Black; int lux = x_offset + chart_lpadding; int luy = y_offset + CHART_UPADDING; bool minorX = graphDef.MinorGridX; bool minorY = graphDef.MinorGridY; bool majorX = graphDef.MajorGridX; bool majorY = graphDef.MajorGridY; Color minColor = graphDef.MinorGridColor; Color majColor = graphDef.MajorGridColor; // Dashed line dashPen.DashStyle = DashStyle.Dot; // Draw basic axis int tmpx = lux + chartWidth; int tmpy = luy + chartHeight; // Draw X axis with arrow defaultPen.Color = graphDef.AxisColor; g.DrawLine(defaultPen, lux - 4, tmpy, tmpx + 4, tmpy); defaultPen.Color = graphDef.ArrowColor; g.DrawLine(defaultPen, tmpx + 4, tmpy - 3, tmpx + 4, tmpy + 3); g.DrawLine(defaultPen, tmpx + 4, tmpy - 3, tmpx + 9, tmpy); g.DrawLine(defaultPen, tmpx + 4, tmpy + 3, tmpx + 9, tmpy); // Draw X axis time grid and labels if (graphDef.GridX) { TimeMarker[] timeList = tGrid.TimeMarkers; bool labelCentered = tGrid.CenterLabels; long labelGridWidth = tGrid.MajorGridWidth; int pixWidth = 0; if (labelCentered) { pixWidth = (chartGraph.GetX(labelGridWidth) - chartGraph.GetX(0)); } for (int i = 0; i < timeList.Length; i++) { long secTime = timeList[i].Timestamp; int posRel = chartGraph.GetX(secTime); int pos = lux + posRel; string label = timeList[i].Label; stringLength = g.MeasureString(label, ft, 1000, sf); if (posRel >= 0) { if (majorX && timeList[i].IsLabel) { dashPen.Color = majColor; g.DrawLine(dashPen, pos, luy, pos, luy + chartHeight); defaultPen.Color = majColor; g.DrawLine(defaultPen, pos, luy - 2, pos, luy + 2); g.DrawLine(defaultPen, pos, luy + chartHeight - 2, pos, luy + chartHeight + 2); // Only draw label itself if we are far enough from the side axis // Use extra 2 pixel padding (3 pixels from border total at least) int txtDistance = (int)(stringLength.Width) / 2; if (labelCentered) { if (pos + pixWidth <= lux + chartWidth) { GraphString(g, ft, label, pos + 2 + pixWidth / 2 - txtDistance, luy + chartHeight + LINE_PADDING); } } else if ((pos - lux > txtDistance + 2) && (pos + txtDistance + 2 < lux + chartWidth)) { GraphString(g, ft, label, pos - txtDistance, luy + chartHeight + LINE_PADDING); } } else if (minorX) { dashPen.Color = minColor; g.DrawLine(dashPen, pos, luy, pos, luy + chartHeight); defaultPen.Color = minColor; g.DrawLine(defaultPen, pos, luy - 1, pos, luy + 1); g.DrawLine(defaultPen, pos, luy + chartHeight - 1, pos, luy + chartHeight + 1); } } } } // Draw Y axis value grid and labels valueFormat.SetScaling(true, false); // always scale the label values if (graphDef.GridY) { ValueMarker[] valueList = vGrid.ValueMarkers; for (int i = 0; i < valueList.Length; i++) { int valRel = chartGraph.GetY(valueList[i].Value); valueFormat.SetFormat(valueList[i].Value, 2, 0); string label = (valueFormat.ScaledValue + " " + valueFormat.Prefix).Trim(); stringLength = g.MeasureString(label, ft, 1000, sf); if (majorY && valueList[i].IsMajor) { dashPen.Color = majColor; g.DrawLine(dashPen, graphOriginX, graphOriginY - valRel, graphOriginX + chartWidth, graphOriginY - valRel); defaultPen.Color = majColor; // solid dashes at ends of lines g.DrawLine(defaultPen, graphOriginX - 2, graphOriginY - valRel, graphOriginX + 2, graphOriginY - valRel); g.DrawLine(defaultPen, graphOriginX + chartWidth - 2, graphOriginY - valRel, graphOriginX + chartWidth + 2, graphOriginY - valRel); GraphString(g, ft, label, graphOriginX - (int)(stringLength.Width) - 7, graphOriginY - valRel - (int)(nfont_height / 2)); } else if (minorY) { dashPen.Color = minColor; g.DrawLine(dashPen, graphOriginX, graphOriginY - valRel, graphOriginX + chartWidth, graphOriginY - valRel); defaultPen.Color = minColor; g.DrawLine(defaultPen, graphOriginX - 1, graphOriginY - valRel, graphOriginX + 1, graphOriginY - valRel); g.DrawLine(defaultPen, graphOriginX + chartWidth - 1, graphOriginY - valRel, graphOriginX + chartWidth + 1, graphOriginY - valRel); } } } }