コード例 #1
0
        protected override void DrawCore(Painter painter, ChartData data)
        {
            base.DrawCore(painter, data);
            if (data != null)
            {
                PaintArguments paintArguments = new PaintArguments(painter, data, ChartMargin);
                int            start          = paintArguments.AxisXLocation;

                try
                {
                    float tmpY     = painter.Height - paintArguments.AxisYLocation;
                    int   interval = CalculateInterval(painter, data);
                    float ratio    = paintArguments.Ratio;
                    foreach (DataSeries dataSeries in data.Series)
                    {
                        painter.DrawString(dataSeries.Name, Style, new ChartPoint(start + interval, tmpY + 2));

                        foreach (DataPoint dataPoint in dataSeries.Point)
                        {
                            start += interval;

                            if (dataPoint.IsValid == true)
                            {
                                ChartPoint[] rectPoint = new ChartPoint[4];
                                float        y         = dataPoint.Value / ratio;
                                rectPoint[0]       = new ChartPoint(start, tmpY - 1);
                                rectPoint[1]       = new ChartPoint(start, tmpY - y);
                                rectPoint[2]       = new ChartPoint(start + interval, tmpY - y);
                                rectPoint[3]       = new ChartPoint(start + interval, tmpY - 1);
                                Style.CurrentColor = Style.ColorList[dataSeries.Point.IndexOf(dataPoint)];
                                painter.DrawPolygon(Style, rectPoint);

                                if (interval > 10)
                                {
                                    painter.DrawString(dataPoint.Value.ToString(), Style, new ChartPoint(start, tmpY - y - 15));
                                }
                            }
                        }
                        start += interval;
                    }
                }
                catch (IndexOutOfRangeException exception)
                {
                    exception.Source = "Check the Painter whether is error./n Check the data source whether is error.";
                    throw exception;
                }
            }
        }
コード例 #2
0
        private void DrawLegend(Painter painter, string[] legends)
        {
            //Four points to draw rectangle
            ChartPoint[]   rectanglePoint = new ChartPoint[4];
            ChartPoint     labelPoint;
            PaintArguments paintArguments = new PaintArguments(painter, null, chartMargin);
            float          tmpX           = paintArguments.AxisXLocation + paintArguments.AxisWidth + 15;

            for (int i = 0; i < legends.Length; i++)
            {
                //Set four points to draw legend rectangle
                float tmpY = painter.Height - paintArguments.AxisYLocation - paintArguments.AxisHeight + i * 10;
                rectanglePoint[0]  = new ChartPoint(tmpX, tmpY);
                rectanglePoint[1]  = new ChartPoint(tmpX + 6, tmpY);
                rectanglePoint[2]  = new ChartPoint(tmpX + 6, tmpY + 5);
                rectanglePoint[3]  = new ChartPoint(tmpX, tmpY + 5);
                style.CurrentColor = style.ColorList[i];
                painter.DrawPolygon(style, rectanglePoint);

                //Set point to draw legend string
                labelPoint = new ChartPoint(tmpX + 8, tmpY - 5);
                painter.DrawString(legends[i], style, labelPoint);
            }
        }