예제 #1
0
        /// <summary>
        /// Suggests a scale for the base axis (independent values).
        /// </summary>
        /// <returns>
        /// A suitable <see cref="TextScale"/> with ticks between the text labels.
        /// </returns>
        public AxisScale SuggestBaseScale()
        {
            if (Data == null || Data.Count == 0)
            {
                return(null);
            }

            CultureInfo culture     = ChartHelper.GetCulture(this);
            Orientation orientation = EffectiveOrientation;

            if (Data.Count == 1)
            {
                DataPoint data      = Data[0];
                double    value     = (orientation == Orientation.Vertical) ? data.X : data.Y;
                TextScale textScale = new TextScale(value - 0.5, value + 0.5);
                textScale.Labels.Add(new TextLabel(value, value.ToString(culture), null));
                textScale.TicksBetweenLabels = true;
                return(textScale);
            }
            else
            {
                DataPoint dataN       = Data[0];
                DataPoint dataNPlus1  = Data[1];
                DataPoint dataNMinus2 = Data[Data.Count - 2];
                DataPoint dataNMinus1 = Data[Data.Count - 1];
                double    valueN;
                double    valueNPlus1;
                double    valueNMinus2;
                double    valueNMinus1;
                if (orientation == Orientation.Vertical)
                {
                    valueN       = dataN.X;
                    valueNPlus1  = dataNPlus1.X;
                    valueNMinus2 = dataNMinus2.X;
                    valueNMinus1 = dataNMinus1.X;
                }
                else
                {
                    valueN       = dataN.Y;
                    valueNPlus1  = dataNPlus1.Y;
                    valueNMinus2 = dataNMinus2.Y;
                    valueNMinus1 = dataNMinus1.Y;
                }

                double    min       = valueN - (valueNPlus1 - valueN) / 2;
                double    max       = valueNMinus1 + (valueNMinus1 - valueNMinus2) / 2;
                TextScale textScale = new TextScale(min, max)
                {
                    TicksBetweenLabels = true
                };
                for (int i = 0; i < Data.Count; i++)
                {
                    DataPoint data  = Data[i];
                    double    value = (orientation == Orientation.Vertical) ? data.X : data.Y;
                    textScale.Labels.Add(new TextLabel(value, value.ToString(culture), null));
                }
                return(textScale);
            }
        }
예제 #2
0
        /// <summary>
        /// Updates the chart when the data has been changed. (Optional - The data source is
        /// updated automatically when the chart is drawn.)
        /// </summary>
        public void UpdateDataSource()
        {
            if (_isDataSourceValid)
            {
                return;
            }

            Data = null;

            Axis xAxis = XAxis;
            Axis yAxis = YAxis;

            if (xAxis == null || yAxis == null)
            {
                // Postpone update until axes are set.
                return;
            }

            CultureInfo       culture = ChartHelper.GetCulture(this);
            IList <TextLabel> xLabels = GetLabels(xAxis);
            IList <TextLabel> yLabels = GetLabels(yAxis);

            Data = ChartDataHelper.CreateChartDataSource(DataSource, XValuePath, YValuePath, XYValuePath, culture, xLabels, yLabels);

#if DEBUG
            ValidateData();
#endif

            _isDataSourceValid = true;

            if (xAxis.AutoScale)
            {
                xAxis.Invalidate();
            }

            if (yAxis.AutoScale)
            {
                yAxis.Invalidate();
            }
        }