protected override void DrawTicks(PdfCanvas canvas, PdfPage page) { base.DrawTicks(canvas, page); try { float lastTickValue = float.Parse(_data.Columns[0].Label); iText.Layout.Canvas layoutCanvas = new iText.Layout.Canvas(canvas, _pdf, new iText.Kernel.Geom.Rectangle(_canvasWidth, _canvasHeight)); layoutCanvas.SetFont(_font); layoutCanvas.SetFontSize(_valueFontSize); layoutCanvas.SetFontColor(_valueFontColour); canvas.SetLineWidth(_tickLineWidth).SetStrokeColor(_tickColour); float x = _originX; foreach (Column column in _data.Columns) { float y = _originY; float columnValue = float.Parse(column.Label); if (columnValue >= (lastTickValue + _lineXTicksInterval)) { lastTickValue = columnValue; canvas.MoveTo(x, _originY); canvas.LineTo(x, _originY + _axisHeight * _yScale); if (_columnLabelAngle == 0.0f) { layoutCanvas.ShowTextAligned(column.Label, x, _originY - _columnLabelMargin, TextAlignment.CENTER, VerticalAlignment.TOP, (float)Math.PI / 180.0f * _columnLabelAngle); } else if (_columnLabelAngle == 90.0f) { layoutCanvas.ShowTextAligned(column.Label, x, _originY - _columnLabelMargin, TextAlignment.RIGHT, VerticalAlignment.MIDDLE, (float)Math.PI / 180.0f * _columnLabelAngle); } else { layoutCanvas.ShowTextAligned(column.Label, x, _originY - _columnLabelMargin, TextAlignment.RIGHT, VerticalAlignment.TOP, (float)Math.PI / 180.0f * _columnLabelAngle); } } x += _linePointSpace; } canvas.Stroke(); } catch { // not numeric column values, bail return; } }
protected override void DrawLabels(PdfCanvas canvas, PdfPage page) { iText.Layout.Canvas layoutCanvas = new iText.Layout.Canvas(canvas, _pdf, new iText.Kernel.Geom.Rectangle(_canvasWidth, _canvasHeight)); layoutCanvas.SetFont(_font); layoutCanvas.SetFontSize(_valueFontSize); layoutCanvas.SetFontColor(_valueFontColour); float x; if (_data.ValueLabel != null) { x = _originX - _valueLabelMargin; layoutCanvas.ShowTextAligned(_data.ValueLabel, x, _originY + _axisHeight * _yScale / 2, TextAlignment.CENTER, VerticalAlignment.MIDDLE, 0.5f * (float)Math.PI); } if (_data.Legends.Count == 1) { layoutCanvas.ShowTextAligned(_data.Legends[0].Label, _originX + _axisWidth / 2, _originY - _valueLabelMargin, TextAlignment.CENTER, VerticalAlignment.MIDDLE, 0); } }
protected override void DrawTicks(PdfCanvas canvas, PdfPage page) { float i; String text; float textWidth; float textHeight; double yOffset = 0; if (_tickLineWidth == 0.0f) { return; } if (_yAxisMin < 0) { yOffset = _yAxisMin * -1.0 * _yScale; } canvas.SetLineWidth(_tickLineWidth).SetStrokeColor(_tickColour); // DrawTicks for (i = (_yAxisMin + _valueAxisInterval); i <= _valueAxisMax; i += _valueAxisInterval) { text = i.ToString(); if (_data.FormatPercent) { text = text + "%"; } textWidth = _font.GetWidth(text, _tickFontSize) + _tickLabelMargin; textHeight = _font.GetAscent(text, _tickFontSize) + _font.GetDescent(text, _tickFontSize); canvas.MoveTo(_originX, _originY + i * _yScale + yOffset); canvas.LineTo(_originX + _axisWidth, _originY + i * _yScale + yOffset); canvas.BeginText() .SetFontAndSize(_font, _tickFontSize) .MoveText(_originX - textWidth, _originY + i * _yScale - textHeight / 2 + yOffset) .SetColor(_tickFontColour, true) .ShowText(text) .EndText(); } canvas.Stroke(); if (_lineXTicks) { float lastTickValue = float.Parse(_data.Columns[0].Label); iText.Layout.Canvas layoutCanvas = new iText.Layout.Canvas(canvas, _pdf, new iText.Kernel.Geom.Rectangle(_canvasWidth, _canvasHeight)); layoutCanvas.SetFont(_font); layoutCanvas.SetFontSize(_valueFontSize); layoutCanvas.SetFontColor(_valueFontColour); canvas.SetLineWidth(_tickLineWidth).SetStrokeColor(_tickColour); float x = _originX; int xIndex = 0; for (xIndex = 0; xIndex < _pointCount; xIndex += (int)_lineXTicksInterval) { float y = _originY; canvas.MoveTo(_originX + xIndex * _linePointSpace, _originY); canvas.LineTo(_originX + xIndex * _linePointSpace, _originY + _axisHeight * _yScale); } canvas.Stroke(); } }