public Bar() { //Initalize variables nWidthBar = 10; nWidthBorderOfBarLine = 2; nGapBarOfColumn = 4; nGapColumns = 8; colBorderOfBar = SystemColors.WindowText; bMouseEnterBar = false; barLocation = new List <ItemDrawInfo>(); //For not throw exception,If mouse move event fire itemLastBarEnter = new ItemDrawInfo(); SecondDataMemberIndependentZero = false; }
private void Chart_MouseMove(object sender, MouseEventArgs e) { if (rcChartDrawArea.Contains(e.Location)) { //Bar enter exit if (bMouseEnterBar) { if (!itemLastBarEnter.Rect.Contains(e.Location)) { bMouseEnterBar = false; OnMouseLeaveBar(itemLastBarEnter.ColIndex, itemLastBarEnter.RowIndex); itemLastBarEnter.ColIndex = itemLastBarEnter.RowIndex = -1; } } if (!bMouseEnterBar) { foreach (ItemDrawInfo item in barLocation) { if (item.Rect.Contains(e.Location)) { bMouseEnterBar = true; itemLastBarEnter = item; OnMouseEnterBar(itemLastBarEnter.ColIndex, itemLastBarEnter.RowIndex); break; } } } } else { if (bMouseEnterBar) { bMouseEnterBar = false; OnMouseLeaveBar(itemLastBarEnter.ColIndex, itemLastBarEnter.RowIndex); } } }
public void NearestBar(Point point, out int rowIndex, out int colIndex) { rowIndex = colIndex = -1; if (barLocation.Count != 0) { ItemDrawInfo l = barLocation[0]; ItemDrawInfo g = barLocation[barLocation.Count - 1]; int xl = l.Rect.Left + l.Rect.Width / 2; int xg = g.Rect.Left + g.Rect.Width / 2; bool bR2L = Parent.Chart.IsRTL(); if (bR2L) { ItemDrawInfo e = l; l = g; g = e; int xe = xl; xl = xg; xg = xe; } foreach (ItemDrawInfo idi in barLocation) { int x = idi.Rect.Left + idi.Rect.Width / 2; if (x > xl && x <= point.X) { l = idi; xl = x; } if (x < xg && x >= point.X) { g = idi; xg = x; } } if (xl == xg) { rowIndex = l.RowIndex; colIndex = l.ColIndex; } else { int x1 = Math.Abs(xl - point.X); int x2 = Math.Abs(xg - point.X); if (x1 > x2) { rowIndex = g.RowIndex; colIndex = g.ColIndex; } else { rowIndex = l.RowIndex; colIndex = l.ColIndex; } } } }
protected override void InternalPaintChart(Graphics grChart, IBindingData data, Rectangle rcArea, ref double xAxisBetweenTextSpace, ref double xAxisTextWidth ) { bool bR2L = Parent.Chart.IsRTL(); Pen penLine = new Pen(colBorderOfBar, nWidthBorderOfBarLine); //Draw bars if ((int)rcChartDrawArea.Height > 0 && (int)rcChartDrawArea.Width > 0) { int xDraw = nGapColumns; double maxminHeight = (double)(rcChartDrawArea.Height / (MaxInTopOfChartArea - MinInBottomOfChartArea)); double xScale = 1; if (SizingModeLabel == SizingModeLabel.Fit || SizingModeLabel == SizingModeLabel.FitIfLarge) { int x = xDraw; x += data.ColumnCount * data.RowCount * nWidthBar; x += nGapBarOfColumn * (data.RowCount - 1) * data.ColumnCount; x += nGapColumns * (data.ColumnCount - 1); x += nGapBarOfColumn; //For space end Axis and last bar xScale = rcChartDrawArea.Width / (double)x; } if (SizingModeLabel == SizingModeLabel.FitIfLarge && xScale > 1) { xScale = 1; } xAxisBetweenTextSpace = nGapColumns * xScale; xAxisTextWidth = data.RowCount * nWidthBar + (data.RowCount - 1) * nGapBarOfColumn; xAxisTextWidth *= xScale; Color[] colBarInner = Parent.Chart.Colors; Brush[] brBar = new Brush[colBarInner.Length]; for (int i = 0; i < colBarInner.Length; i++) { brBar[i] = new SolidBrush(colBarInner[i]); } int nWidthBarWithScale = (int)(nWidthBar * xScale); for (int colIndex = 0; colIndex < data.ColumnCount; colIndex++) { if (!drawAllDataField) { break; } #region Draw bars int selectedBarColor = 0; for (int rowIndex = 0; rowIndex < data.RowCount; rowIndex++) { double d = data.ValueDouble(rowIndex, colIndex); bool isOverflow = false; if (d > 0 && d > MaxInTopOfChartArea) { isOverflow = true; d = MaxInTopOfChartArea; } if (d < 0 && d < MinInBottomOfChartArea) { isOverflow = true; d = MinInBottomOfChartArea; } int yMustDraw = (int)(d * maxminHeight); if (yMustDraw == 0) { yMustDraw = nWidthBorderOfBarLine; } Rectangle rcDraw; int xDraw2 = 0; if (bR2L) { xDraw2 = (int)rcChartDrawArea.Right - (int)(xDraw * xScale) - nWidthBarWithScale; } else { xDraw2 = (int)(xDraw * xScale) + (int)rcChartDrawArea.Left; } if (yMustDraw >= 0) { rcDraw = new Rectangle( xDraw2, AxisFromTop - yMustDraw, nWidthBarWithScale, yMustDraw); } else { rcDraw = new Rectangle( xDraw2, AxisFromTop, nWidthBarWithScale, -yMustDraw); } if (rcChartDrawArea.Contains(rcDraw)) { bool bValidValue = data.Valid(rowIndex, colIndex); if (bValidValue) { grChart.FillRectangle(brBar[selectedBarColor], rcDraw); } ItemDrawInfo item = new ItemDrawInfo { Rect = rcDraw, IsOverflow = isOverflow, ColIndex = colIndex, RowIndex = rowIndex }; barLocation.Add(item); if (bValidValue) { if (nWidthBorderOfBarLine > 0 || d == 0) { grChart.DrawRectangle(penLine, rcDraw); } if (isOverflow && rcDraw.Height > nWidthBorderOfBarLine * 2) { if (d > 0) { grChart.DrawLine(penLine, rcDraw.Left, rcDraw.Top - nWidthBorderOfBarLine, rcDraw.Right, rcDraw.Top - nWidthBorderOfBarLine); } else if (d < 0) { grChart.DrawLine(penLine, rcDraw.Left, rcDraw.Bottom + nWidthBorderOfBarLine, rcDraw.Right, rcDraw.Bottom + nWidthBorderOfBarLine); } } } } else { drawAllDataField = false; break; } xDraw += (nWidthBar + nGapBarOfColumn); selectedBarColor++; selectedBarColor %= brBar.Length; } #endregion xDraw -= nGapBarOfColumn; xDraw += nGapColumns; } for (int i = 0; i < colBarInner.Length; i++) { brBar[i].Dispose(); } } penLine.Dispose(); }