Ejemplo n.º 1
0
        protected override void drawCartesianChart(Graphics g, Rectangle bound) {
            // Draw line.
            // TODO: Need to check whether the points are connected or not.
            foreach (Series series in DataSource.SeriesCollection) {
                if (series.DataPoints.Count == 0) {
                    continue;
                }

                PointF[] points = new PointF[series.DataPoints.Count];
                string[] labels = new String[series.DataPoints.Count];
                int index = 0;
                foreach (XYDataPoint data in series.DataPoints) {
                    points[index] = new PointF(data.X, data.Y);
                    labels[index++] = String.Format("({0},{1})", data.X, data.Y);
                }
                transformPoints(points);
                g.DrawLines(new Pen(series.Color,2), points);

                // Draw symbol. Default is circle.
                index = 0;
                foreach (PointF point in points) {
                    g.FillEllipse(new SolidBrush(series.Color), point.X - 2, point.Y - 2, 4, 4);
//                    if (c.getPointLabelFormat() != POINT_LABEL_NONE) {
//                        String label = null;
//                        String xy_label = null;
//
//                        try {
//                            DecimalFormat df = new DecimalFormat(xy_label_format);
//                            xy_label = "(" + df.format(c.x) + ", " + df.format(c.y) + ")";
//                        } catch (Exception exc) {}
//                        if (c.getPointLabelFormat() == POINT_LABEL_XY)
//                            label = xy_label;
//                        else if (c.getPointLabelFormat() == POINT_LABEL_NAME)
//                            label = c.name;
//                        else if (c.getPointLabelFormat() == POINT_LABEL_FULL)
//                            label = c.name + xy_label;
//
					if(mDrawCoordinates) 
					{
						Label label = new Label(labels[index++]);
						label.Position = new PointF(point.X, point.Y - 8);
						label.HorizontalAlign = HorizontalAlign.Center;
						label.VerticalAlign = VerticalAlign.Bottom;
						label.draw(g);
					}

//                        adlabel.setGraphics(g);
//                        if (c.getPointLabelPosition() == POINT_LABEL_POSITION_TOP) {
//                            adlabel.setPosition(pt.x, pt.y - symbol.getSize() - 3);
//                            adlabel.setAlign(B_CENTER);
//                        }
//                        else if (c.getPointLabelPosition() == POINT_LABEL_POSITION_BOTTOM) {
//                            adlabel.setPosition(pt.x, pt.y + symbol.getSize() + 3);
//                            adlabel.setAlign(T_CENTER);
//                        }
//                        else if (c.getPointLabelPosition() == POINT_LABEL_POSITION_LEFT) {
//                            adlabel.setPosition(pt.x - symbol.getSize() - 3, pt.y);
//                            adlabel.setAlign(M_RIGHT);
//                        }
//                        else if (c.getPointLabelPosition() == POINT_LABEL_POSITION_RIGHT) {
//                            adlabel.setPosition(pt.x + symbol.getSize() + 3, pt.y);
//                            adlabel.setAlign(M_LEFT);
//                        }
//                        adlabel.draw();

                }
            }
        }
Ejemplo n.º 2
0
        protected override void drawCartesianChart(Graphics g, Rectangle bound) {
            int numOfSeries = DataSource.SeriesCollection.Count;

            float oldValue = 0.0F;
            int columnPerGroup = numOfSeries;
            int columnIndex = 0;
            int groupIndex = 0;

            if (m_enableStackChart) {
                columnPerGroup = 1;
            }
            for (int index = 0; index < m_categoryNames.Count; index++) {
                ArrayList listValues = (ArrayList) m_hashTable[(string) m_categoryNames[index]];
                oldValue = 0.0F;
                ArrayList list = new ArrayList();
                foreach (DataPoint data in listValues) {
                    list.Add(data);
                }
                if (m_enableStackChart) {
                    list.Sort(new AscendingDataComparer());
                }

                for (int index1 = 0; index1 < list.Count; index1++) {
                    DataPoint data = (DataPoint) list[index1];
                    if (m_enableStackChart || numOfSeries == 1) {
                        columnIndex = 0;
                    } else {
                        columnIndex = index1;
                    }
                    groupIndex =index;

                    Label label = null;
                    
                    PointF[] pts = new PointF[2];
                    if (m_orientation == Orientation.Vertical) {
                        pts[0] = new PointF(groupIndex + .75F + columnIndex * .5F / columnPerGroup, data.Value);
                        pts[1] = new PointF(groupIndex + .75F + (columnIndex + 1) * .5F / columnPerGroup, oldValue);

                        transformPoints(pts);
                        int labelGap;
                        label = new Label(data.Value.ToString("#.##"));

                        if (data.Value <= 0) {
                            labelGap = 5;
                            label.VerticalAlign = VerticalAlign.Top;
                        } else {
                            labelGap = -5;
                            label.VerticalAlign = VerticalAlign.Bottom;
                        }
                        label.Position = new PointF((pts[0].X + pts[1].X) / 2, pts[0].Y + labelGap);
                        label.HorizontalAlign = HorizontalAlign.Center;

                    } else {
                        pts[0] = new PointF(oldValue, groupIndex + .75F + (columnIndex + 1) *.5F / columnPerGroup);
                        pts[1] = new PointF(data.Value, groupIndex + .75F + (columnIndex * .5F / columnPerGroup));
                        transformPoints(pts);

                        int labelGap;
                        label = new Label(data.Value.ToString());
                        if (data.Value <= 0) {
                            labelGap = -15;
                            label.HorizontalAlign = HorizontalAlign.Right;
                        } else {
                            labelGap = 15;
                            label.HorizontalAlign = HorizontalAlign.Left;
                        }
                        label.Position = new PointF(pts[1].X + labelGap, (pts[0].Y + pts[1].Y) / 2);
                        label.VerticalAlign = VerticalAlign.Middle;

                    }
                    draw3DRect(g,data.Color, new RectangleF(pts[0].X, pts[0].Y, pts[1].X - pts[0].X, pts[1].Y - pts[0].Y), Depth);
                    //
                    //                    if (show_label)
                    //                        label_value.draw();
                    if (IsShowLabel)
                        label.draw(g);
                    if (m_enableStackChart && data.Value > 0) {
                        oldValue = data.Value;
                    } else {
                        oldValue = 0.0F;
                    }
                }

            }


        }
Ejemplo n.º 3
0
 private void setMaxXLabelHeight(Graphics g)
 {
     for (int index = 0; index <= this[AxisType.Bottom].MajorTickCount; index++) {
         if (index < m_xLabelList.Length) {
             Label label = new Label(m_xLabelList[index]);
             if (label.getHeight(g) > m_maxXLabelHeight)
                 m_maxXLabelHeight = label.getHeight(g);
         }
     }
 }
Ejemplo n.º 4
0
 private void setMaxYLabelWidth(Graphics g)
 {
     for (int index = 0; index <= this[AxisType.Left].MajorTickCount; index++) {
         if (index < m_yLabelList.Length) {
             Label label = new Label(m_yLabelList[index]);
             if (label.getWidth(g) > m_maxYLabelWidth)
                 m_maxYLabelWidth = label.getWidth(g);
         }
     }
 }
Ejemplo n.º 5
0
        private void drawCartesianPlane(Graphics g, Rectangle bound)
        {
            calculateVertices(g, bound);

            Point[] leftSide = new Point[4];
            leftSide[0] = m_vertices[0];
            leftSide[1] = m_vertices[1];
            leftSide[2] = m_vertices[2];
            leftSide[3] = m_vertices[7];

            Point[] backSide = new Point[4];
            backSide[0] = m_vertices[2];
            backSide[1] = m_vertices[3];
            backSide[2] = m_vertices[6];
            backSide[3] = m_vertices[7];

            Point[] bottomSide = new Point[4];
            bottomSide[0] = m_vertices[0];
            bottomSide[1] = m_vertices[7];
            bottomSide[2] = m_vertices[6];
            bottomSide[3] = m_vertices[5];

            g.FillPolygon(new SolidBrush(Color.LightGray), leftSide);
            g.FillPolygon(new SolidBrush(Color.DarkGray), bottomSide);

            #region Draw x axis at y = 0;
            PointF[] pts = new PointF[2];
            pts[0] = new PointF(0, 0);
            pts[1] = new PointF(m_xmin, m_ymin);
            transformPoints(pts);

            Matrix matrix = new Matrix();
            matrix.Translate(0, pts[0].Y - pts[1].Y);
            matrix.TransformPoints(bottomSide);
            g.FillPolygon(new SolidBrush(Color.DarkGray), bottomSide);
            #endregion

            #region Draw y axis at x = 0
            matrix.Reset();
            matrix.Translate(pts[0].X - pts[1].X, 0);
            matrix.TransformPoints(leftSide);
            g.FillPolygon(new SolidBrush(Color.LightGray), leftSide);
            #endregion
            Axis bottomAxis = this[AxisType.Bottom];
            Axis topAxis = this[AxisType.Top];
            Axis leftAxis = this[AxisType.Left];
            Axis rightAxis = this[AxisType.Right];

            #region Draw axises
            // Draw axises.
            // TODO: Is there a way to simplify these lines to loop.
            if (leftAxis.Visible)
            {
                g.DrawLine(new Pen(leftAxis.Color), m_vertices[0], m_vertices[1]);
            }
            if (rightAxis.Visible)
            {
                g.DrawLine(new Pen(rightAxis.Color), m_vertices[3], m_vertices[6]);
                g.DrawLine(new Pen(rightAxis.Color), m_vertices[5], m_vertices[6]);
            }
            if (bottomAxis.Visible)
            {
                g.DrawLine(new Pen(bottomAxis.Color), m_vertices[0], m_vertices[5]);
            }
            if (topAxis.Visible)
            {
                g.DrawLine(new Pen(topAxis.Color), m_vertices[1], m_vertices[2]);
                g.DrawLine(new Pen(topAxis.Color), m_vertices[2], m_vertices[3]);
            }

            #endregion
            #region Draw vertical label.
            if (DataSource.VerticalTitle != null)
            {
                Label title = new Label(DataSource.VerticalTitle);
                title.Position = new PointF(m_vertices[0].X - m_maxYLabelWidth - 5, (m_vertices[0].Y + m_vertices[1].Y) / 2);
                title.RotateAngle = -90;
                title.HorizontalAlign = HorizontalAlign.Center;
                title.VerticalAlign = VerticalAlign.Bottom;
                title.draw(g);
            }
            #endregion
            #region Draw horizontal label.
            if (DataSource.HorizontalTitle != null)
            {
                Label title = new Label(DataSource.HorizontalTitle);
                title.Position = new PointF((m_vertices[0].X + m_vertices[5].X) / 2 , m_vertices[0].Y + m_maxXLabelHeight + 5);
                title.VerticalAlign = VerticalAlign.Top;
                title.HorizontalAlign = HorizontalAlign.Center;
                title.draw(g);
            }
            #endregion
            #region Draw vertical grid, major & minor tick.
            // Draw grid & major & minor tick
            float dx = (bound.Width - this.Depth) / (bottomAxis.MajorTickCount - 1);
            float dx1 = dx / bottomAxis.MinorTickCount;

            int i = 0;
            float majorOffset = 0.0F;
            for (i = 0, majorOffset = 0.0F; i < bottomAxis.MajorTickCount; i++, majorOffset += dx)
            {
                if (i == (bottomAxis.MajorTickCount - 1))
                {
                    majorOffset = bound.Width - this.Depth;

                }
                if (m_enableVerticalGrid)
                {
                    Pen pen = new Pen(Color.Black);
                    g.DrawLine(pen, m_vertices[0].X + majorOffset, m_vertices[0].Y, m_vertices[7].X + majorOffset, m_vertices[7].Y);
                    g.DrawLine(pen, m_vertices[7].X + majorOffset, m_vertices[7].Y, m_vertices[2].X + majorOffset, m_vertices[2].Y);
                }
                //
                //                g.setColor(tick_color);
                int i1;
                float minorOffset;
                Pen tickPen = new Pen(bottomAxis.TickColor);
                for (i1 = 0, minorOffset = majorOffset; i1 < bottomAxis.MinorTickCount && i != (bottomAxis.MajorTickCount - 1); i1++, minorOffset += dx1)
                {
                    //                    if (draw_tick_mark[BOTTOM_AXIS][MINOR_TICK])
                    //                        g.drawLine(vertices[0].x + (int) minor_offset, vertices[0].y - tick_length[BOTTOM_AXIS][MINOR_TICK], vertices[0].x + (int) minor_offset, vertices[0].y);
                    if (BottomAxis.Visible && BottomAxis.EnableMinorTick)
                    {
                        g.DrawLine(tickPen,
                            m_vertices[0].X + minorOffset,
                            m_vertices[0].Y - bottomAxis.MinorTickLength,
                            m_vertices[0].X + minorOffset,
                            m_vertices[0].Y);
                    }

                    //                    if (draw_tick_mark[TOP_AXIS][MINOR_TICK])
                    //                        g.drawLine(vertices[2].x + (int) minor_offset, vertices[2].y + tick_length[TOP_AXIS][MINOR_TICK], vertices[2].x + (int) minor_offset, vertices[2].y);
                    if (TopAxis.Visible && TopAxis.EnableMinorTick)
                    {
                        g.DrawLine(tickPen,
                            m_vertices[2].X + minorOffset,
                            m_vertices[2].Y + topAxis.MinorTickLength,
                            m_vertices[2].X + minorOffset,
                            m_vertices[2].Y);
                    }
                }
                //
                //                if (draw_tick_mark[BOTTOM_AXIS][MAJOR_TICK])
                //                    g.drawLine(vertices[0].x + (int) major_offset, vertices[0].y - tick_length[BOTTOM_AXIS][MAJOR_TICK], vertices[0].x + (int) major_offset, vertices[0].y);
                if (BottomAxis.Visible && BottomAxis.EnableMajorTick)
                {
                    g.DrawLine(tickPen,
                        m_vertices[0].X + majorOffset,
                        m_vertices[0].Y - bottomAxis.MajorTickLength,
                        m_vertices[0].X + majorOffset,
                        m_vertices[0].Y);
                }

                //                if (draw_tick_mark[TOP_AXIS][MAJOR_TICK])
                //                    g.drawLine(vertices[2].x + (int) major_offset, vertices[2].y + tick_length[TOP_AXIS][MAJOR_TICK], vertices[2].x + (int) major_offset, vertices[2].y);
                if (TopAxis.Visible && TopAxis.EnableMajorTick)
                {
                    g.DrawLine(tickPen,
                        m_vertices[2].X + majorOffset,
                        m_vertices[2].Y + bottomAxis.MajorTickLength,
                        m_vertices[2].X + majorOffset,
                        m_vertices[2].Y);
                }

                if (i < m_xLabelList.Length )
                {
                    string strLabel=m_xLabelList[i];
                    if(strLabel!=null)
                    {
                        if(strLabel.IndexOf("::")==-1 && strLabel.IndexOf("\\")==-1)
                        {
                            Label label = new Label(strLabel);
                            label.Position = new Point(m_vertices[0].X + (int) majorOffset, m_vertices[0].Y);
                            label.VerticalAlign = VerticalAlign.Top;
                            label.HorizontalAlign = HorizontalAlign.Center;
                            label.draw(g);

                        }
                    }
                    else
                    {
                        Label label = new Label(strLabel);
                        label.Position = new Point(m_vertices[0].X + (int) majorOffset, m_vertices[0].Y);
                        label.VerticalAlign = VerticalAlign.Top;
                        label.HorizontalAlign = HorizontalAlign.Center;
                        label.draw(g);
                    }

                }

                //                if (i < x_label_list.length) {
                //                    if (label_major_tick[BOTTOM_AXIS]) {
                //                        adLabel label = new adLabel(x_label_list[i]);
                //                        label.setPosition(vertices[0].x + (int) major_offset, vertices[0].y + space);
                //                        label.setNumberFormat(x_label_format);
                //                        label.setAlign(adLabel.T_CENTER);
                //                        label.setGraphics(g);
                //                        label.draw();
                //                    }
                //
                //                    if (label_major_tick[TOP_AXIS]) {
                //                        adLabel label = new adLabel(x_label_list[i]);
                //                        label.setPosition(vertices[2].x + (int) major_offset, vertices[2].y - space);
                //                        label.setAlign(adLabel.B_CENTER);
                //                        label.setNumberFormat(x_label_format);
                //                        label.setGraphics(g);
                //                        label.draw();
                //                    }
                //                }
            }
            #endregion

            #region Draw horizontal grid, major & minor tick.
            float dy = (float) (bound.Height - this.Depth) / ((float) leftAxis.MajorTickCount - 1.0F);
            float dy1 = dy / leftAxis.MinorTickCount;
            for (i = leftAxis.MajorTickCount - 1, majorOffset = 0.0F; i >= 0; i--, majorOffset += dy)
            {
                if (i == 0)
                    majorOffset = bound.Height - this.Depth;
                if (m_enableHorizontalGrid)
                {
                    Pen pen = new Pen(Color.Black);
                    g.DrawLine(pen,
                        m_vertices[1].X,
                        m_vertices[1].Y + majorOffset,
                        m_vertices[2].X,
                        m_vertices[2].Y + majorOffset);
                    g.DrawLine(pen,
                        m_vertices[2].X,
                        m_vertices[2].Y + majorOffset,
                        m_vertices[3].X,
                        m_vertices[3].Y + majorOffset);
                }
                int i1;
                float minorOffset;
                Pen tickPen = new Pen(leftAxis.TickColor);
                for (i1 = 0, minorOffset = majorOffset; i1 < leftAxis.MinorTickCount && i != 0; i1++, minorOffset += dy1)
                {
                    if (LeftAxis.Visible && LeftAxis.EnableMinorTick)
                    {
                        g.DrawLine(tickPen,
                            m_vertices[1].X,
                            m_vertices[1].Y + minorOffset,
                            m_vertices[1].X + leftAxis.MinorTickLength,
                            m_vertices[1].Y + minorOffset);
                    }
                    if (RightAxis.Visible && RightAxis.EnableMinorTick)
                    {
                        g.DrawLine(tickPen,
                            m_vertices[3].X,
                            m_vertices[3].Y + minorOffset,
                            m_vertices[3].X - leftAxis.MinorTickLength,
                            m_vertices[3].Y + minorOffset);
                    }
                }
                if (LeftAxis.Visible && LeftAxis.EnableMajorTick)
                {
                    g.DrawLine(tickPen,
                        m_vertices[1].X,
                        m_vertices[1].Y + majorOffset,
                        m_vertices[1].X + leftAxis.MajorTickLength,
                        m_vertices[1].Y + majorOffset);
                }
                if (RightAxis.Visible && RightAxis.EnableMajorTick)
                {
                    g.DrawLine(tickPen,
                        m_vertices[3].X,
                        m_vertices[3].Y + majorOffset,
                        m_vertices[3].X - leftAxis.MajorTickLength,
                        m_vertices[3].Y + majorOffset);
                }
                if (i < m_yLabelList.Length)
                {
                    Label label = new Label(m_yLabelList[i]);
                    label.Position = new Point(m_vertices[1].X , m_vertices[1].Y + (int) majorOffset);
                    label.HorizontalAlign =HorizontalAlign.Right;
                    label.VerticalAlign = VerticalAlign.Middle;
                    label.draw(g);
                }

            }
            #endregion
        }