Beispiel #1
0
        /// <summary>
        /// Draw a pie chart.
        /// </summary>
        /// <param name="points">Specified points in the series.</param>
        private void DrawPieChart(DataPointCollection points, int pieNo)
        {
            double sizeOfCircle = ((WidthRequest > HeightRequest) ? HeightRequest / 2 : WidthRequest / 2);

            double[] values          = points.Select(p => p.Value).ToArray();
            double   degreesPerValue = 360 / values.Sum();

            for (int i = 0; i < values.Length; i++)
            {
                values[i] = values[i] * degreesPerValue;
            }

            OnDrawPie(this, new DrawEventArgs <PieDrawingData> {
                Data = new PieDrawingData(WidthRequest / 2, HeightRequest / 2, pieNo, sizeOfCircle, values)
            });
        }
Beispiel #2
0
        /// <summary>
        /// Draw text.
        /// </summary>
        /// <param name="highestValue">Highest Y-value possible after drawing the grid.</param>
        /// <param name="widthPerBar">Width of a single bar.</param>
        /// <param name="points">Specified points in the series.</param>
        private void DrawLabels(double highestValue, double widthPerBar, DataPointCollection points)
        {
            int noOfBarSeries = Series.Count(s => s.Type == ChartType.Bar);

            if (noOfBarSeries == 0)
            {
                noOfBarSeries = 1;
            }
            double widthOfAllBars = noOfBarSeries * widthPerBar;
            double widthIterator  = 2 + PADDING_LEFT;

            for (int i = 0; i < points.Count; i++)
            {
                OnDrawText(this, new DrawEventArgs <TextDrawingData>()
                {
                    Data = new TextDrawingData(points[i].Label, (widthIterator + widthOfAllBars / 2) - (points[i].Label.Length * 4), HeightRequest + 25)
                });
                widthIterator += widthPerBar * noOfBarSeries + Spacing;
            }
        }
Beispiel #3
0
 public Series()
 {
     Points = new DataPointCollection();
 }
Beispiel #4
0
        /// <summary>
        /// Draw a line.
        /// </summary>
        /// <param name="highestValue">Highest Y-value possible after drawing the grid.</param>
        /// <param name="widthPerBar">Width of a single bar.</param>
        /// <param name="lineNo">The number of the series</param>
        /// <param name="points">Specified points in the series.</param>
        private void DrawLineChart(double highestValue, double widthPerBar, int lineNo, DataPointCollection points)
        {
            int noOfBarSeries = Series.Count(s => s.Type == ChartType.Bar);

            if (noOfBarSeries == 0)
            {
                noOfBarSeries = 1;
            }
            double widthOfAllBars = noOfBarSeries * widthPerBar;
            double widthIterator  = 2 + PADDING_LEFT;

            List <double> pointsList = new List <double>();

            double[] previousPoints = new double[2];
            for (int i = 0; i < points.Count; i++)
            {
                double heightOfLine = ((HeightRequest - PADDING_TOP) / highestValue) * points[i].Value;

                double x = widthIterator + (widthOfAllBars / 2);
                double y = ((HeightRequest - PADDING_TOP) - heightOfLine) + PADDING_TOP;

                if (i != 0)
                {
                    OnDrawLine(this, new DrawEventArgs <DoubleDrawingData>()
                    {
                        Data = new DoubleDrawingData(previousPoints[0], previousPoints[1], x, y, lineNo)
                    });
                }

                previousPoints[0] = x;
                previousPoints[1] = y;

                OnDrawCircle(this, new DrawEventArgs <SingleDrawingData>()
                {
                    Data = new SingleDrawingData(widthIterator + (widthOfAllBars / 2), ((HeightRequest - PADDING_TOP) - heightOfLine) + PADDING_TOP, lineNo)
                });

                widthIterator += widthPerBar * noOfBarSeries + Spacing;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Draw a bar.
        /// </summary>
        /// <param name="highestValue">Highest Y-value possible after drawing the grid.</param>
        /// <param name="widthPerBar">Width of a single bar.</param>
        /// <param name="barNo">The number of the series</param>
        /// <param name="points">Specified points in the series.</param>
        private void DrawBarChart(double highestValue, double widthPerBar, int barNo, DataPointCollection points)
        {
            double widthIterator = 2 + (barNo * widthPerBar) + PADDING_LEFT;

            foreach (DataPoint point in points)
            {
                double heightOfBar = ((HeightRequest - PADDING_TOP) / highestValue) * point.Value;

                OnDrawBar(this, new DrawEventArgs <DoubleDrawingData>()
                {
                    Data = new DoubleDrawingData(widthIterator + 1, ((HeightRequest - PADDING_TOP) - heightOfBar) + PADDING_TOP, (widthIterator + widthPerBar) - 1, HeightRequest, barNo)
                });

                widthIterator += widthPerBar * Series.Count(s => s.Type == ChartType.Bar) + Spacing;
            }
        }