Esempio n. 1
1
        // copy data from a data source to the chart
        // c1c          chart
        // series       index of the series to bind (0-based, will add if necessary)
        // datasource   datasource object (cannot be DataTable, DataView is OK)
        // field        name of the field that contains the y values
        // labels       name of the field that contains the x labels
        private void BindSeries(C1Chart c1c, int series, object dataSource, string field, string labels)
        {
            // check data source object
            ITypedList il = (ITypedList)dataSource;
            IList list = (IList)dataSource;
            if (list == null || il == null)
                throw new ApplicationException("Invalid DataSource object.");

            // add series if necessary
            ChartDataSeriesCollection coll = c1c.ChartGroups[0].ChartData.SeriesList;
            while (series >= coll.Count)
                coll.AddNewSeries();
            coll[series].LineStyle.Thickness = 2;
            coll[series].SymbolStyle.Shape = SymbolShapeEnum.None;


            // copy series data
            if (list.Count == 0) return;
            PointF[] data = (PointF[])Array.CreateInstance(typeof(PointF), list.Count);
            PropertyDescriptorCollection pdc = il.GetItemProperties(null);
            PropertyDescriptor pd = pdc[field];
            if (pd == null)
                throw new ApplicationException(string.Format("Invalid field name used for Y values ({0}).", field));

            int i;
            double d;
            for (i = 0; i < list.Count; i++)
            {
                data[i].X = i;

                if (Double.TryParse(pd.GetValue(list[i]).ToString(), out d))
                {
                    data[i].Y = float.Parse(pd.GetValue(list[i]).ToString());
                }
                else
                {
                    data[i].Y = float.NaN;
                }
                coll[series].PointData.CopyDataIn(data);
                coll[series].Label = field;
            }

            // copy series labels
            if (labels != null && labels.Length > 0)
            {
                pd = pdc[labels];
                if (pd == null)
                    throw new ApplicationException(string.Format("Invalid field name used for X values ({0}).", labels));
                Axis ax = c1c.ChartArea.AxisX;
                ax.ValueLabels.Clear();
                for (i = 0; i < list.Count; i++)
                {
                    string label = pd.GetValue(list[i]).ToString();
                    ax.ValueLabels.Add(i, label);
                }
                ax.AnnoMethod = AnnotationMethodEnum.ValueLabels;
            }
        }
Esempio n. 2
0
        internal override void UpdateAttachPoint(C1Chart chart, Point offset)
        {
            var prect = chart.View.PlotRect;

            var pt = PointFromData(chart, DataPoint, AxisX, AxisY, offset);

            if (double.IsNaN(pt.X) || double.IsNaN(pt.Y))
            {
                return;
            }

            if (Offset.X != 0 || Offset.Y != 0)
            {
                Canvas.SetLeft(this, pt.X + Offset.X);
                Canvas.SetTop(this, pt.Y + Offset.Y);
            }

            if (AttachPoint.X != 0 && AttachPoint.Y != 0)
            {
                var dx = Canvas.GetLeft(this) - AttachPoint.X;
                var dy = Canvas.GetTop(this) - AttachPoint.Y;
                Canvas.SetLeft(this, pt.X + dx);
                Canvas.SetTop(this, pt.Y + dy);
            }
            else
            {
                SetPosition(pt, Offset);
            }

            AttachPoint = pt;
        }
        private void c1Chart1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            C1Chart chart = (C1Chart)sender;
            int     g = 0, s = -1;

            ChartRegionEnum region = chart.ChartRegionFromCoord(e.X, e.Y);

            if (region.Equals(ChartRegionEnum.Legend))
            {
                Legend leg = chart.Legend;
                if (leg.SeriesFromCoord(e.X, e.Y, ref g, ref s))
                {
                    if (s >= 0)
                    {
                        if (e.Button.Equals(MouseButtons.Left))
                        {
                            CycleSeries(s);
                        }
                        else if (e.Button.Equals(MouseButtons.Right))
                        {
                            ResetSeries(s);
                        }
                        else if (e.Button.Equals(MouseButtons.Middle))
                        {
                            ToggleSeriesDisplay(s);
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        private void Form1_Resize(object sender, System.EventArgs e)
        {
            // resize the charts with each form resize.
            C1Chart chart = chartRawData;

            int w = this.ClientSize.Width - chart.Left;
            int h = chart.Height;

            if (w < 100)
            {
                w = 100;
            }
            chart.Width          = w;
            txtStatistics.Height = h;

            chart       = chartHistogram;
            chart.Width = this.ClientSize.Width;

            chart.Top = h;
            h         = this.ClientSize.Height - h;
            if (h < 100)
            {
                h = 100;
            }
            chart.Height = h;
        }
        /// <summary>
        /// Localizes the specified chart object by adding the specified
        /// prefix in groupBox2 to the beginning of each localizable string.
        ///
        /// Of course, no one would really want to do this, but it
        /// demonstrates how to modify and localize the strings used in the
        /// dialogs and property descriptions.
        /// </summary>
        /// <param name="objChart"></param>
        private void localizeChart(object objChart)
        {
            // a MemoryStream is used for demo purposes.
            MemoryStream ChartLocalizationStream = new MemoryStream();

            if (objChart is C1Chart)
            {
                C1Chart chart = objChart as C1Chart;
                if (chart.SaveLocalizations(ChartLocalizationStream))
                {
                    addPrefixToLocalizations(ChartLocalizationStream);
                    chart.LoadLocalizations(ChartLocalizationStream);
                }
            }
            else if (objChart is C1Chart3D)
            {
                C1Chart3D chart = objChart as C1Chart3D;
                if (chart.SaveLocalizations(ChartLocalizationStream))
                {
                    addPrefixToLocalizations(ChartLocalizationStream);
                    chart.LoadLocalizations(ChartLocalizationStream);
                }
            }

            ChartLocalizationStream.Close();
            ChartLocalizationStream.Dispose();
        }
        Point DataIndexToPoint(C1Chart chart, int seriesIndex, int pointIndex)
        {
            if (chart.ChartType.ToString().StartsWith("Pie"))
            {
                var slices = chart.FindChildren <PieSlice>();

                foreach (var slice in slices)
                {
                    if (slice.DataPoint.SeriesIndex == seriesIndex && slice.DataPoint.PointIndex == pointIndex)
                    {
                        plotCenter = slice.PieCenter;
                        var geom = slice.RenderedGeometry as PathGeometry;
                        var arc  = geom.Figures[0].Segments[1] as ArcSegment;

                        var angle = slice.Angle / 180 * Math.PI;
                        return(new Point(slice.PieCenter.X + arc.Size.Width * Math.Cos(angle),
                                         slice.PieCenter.Y + arc.Size.Height * Math.Sin(angle)));
                    }
                }
                return(new Point());
            }
            else
            {
                return(chart.View.DataIndexToPoint(seriesIndex, pointIndex));
            }
        }
Esempio n. 7
0
        internal override void UpdateAttachPoint(C1Chart chart, Point offset)
        {
            var prect = chart.View.PlotRect;

              var pt = PointFromData(chart, DataPoint, AxisX, AxisY, offset);

              if (double.IsNaN(pt.X) || double.IsNaN(pt.Y))
            return;

              if (Offset.X != 0 || Offset.Y != 0)
              {
            Canvas.SetLeft(this, pt.X + Offset.X);
            Canvas.SetTop(this, pt.Y + Offset.Y);
              }

              if (AttachPoint.X != 0 && AttachPoint.Y != 0)
              {
            var dx = Canvas.GetLeft(this) - AttachPoint.X;
            var dy = Canvas.GetTop(this) - AttachPoint.Y;
            Canvas.SetLeft(this, pt.X + dx);
            Canvas.SetTop(this, pt.Y + dy);
              }
              else
            SetPosition(pt, Offset);

              AttachPoint = pt;
        }
        private void c1Chart1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (e.Button.Equals(MouseButtons.None))
            {
                C1Chart         chart  = (C1Chart)sender;
                ChartRegionEnum region = chart.ChartRegionFromCoord(e.X, e.Y);

                int g = -1, s = -1, p = -1, d = -1;
                if (region.Equals(ChartRegionEnum.Legend))
                {
                    if (chart.Legend.SeriesFromCoord(e.X, e.Y, ref g, ref s))
                    {
                        if (g >= 0 && s >= 0)
                        {
                            chart.Footer.Text = "Series #" + s.ToString();
                        }
                    }
                }
                else
                {
                    ChartGroup grp = chart.ChartGroups[0];
                    if (grp.CoordToDataIndex(e.X, e.Y, CoordinateFocusEnum.XandYCoord, ref s, ref p, ref d))
                    {
                        if (d == 0 && s >= 0 && p >= 0)
                        {
                            chart.Footer.Text = "Slice #" + s.ToString();
                        }
                        else if (!chart.Footer.Text.Equals("Nowhere"))
                        {
                            chart.Footer.Text = "Nowhere";
                        }
                    }
                }
            }
        }
Esempio n. 9
0
        public virtual void Create(C1Chart chart, IDataSeries[] dss, int npts)
        {
            Reset(chart);

              IEnumerable x = null;

              for (int i = 0; i < dss.Length; i++)
              {
            DataSeries ds = null;
            if (i < chart.Data.Children.Count)
            {
              ds = (DataSeries)chart.Data.Children[i];
              dss[i].Update(ds, npts);
            }
            else
              ds = dss[i].Create(npts);

            XYDataSeries xds = ds as XYDataSeries;
            if (xds != null)
            {
              if (x == null)
            x = xds.XValuesSource;
              else
            xds.XValuesSource = x;
            }

            if( !chart.Data.Children.Contains(ds))
              chart.Data.Children.Add(ds);
              }
        }
Esempio n. 10
0
        // Add Chart Labels with beginning and ending dates for each data point
        // in the Gantt chart.  Labels are placed inside on the western edge.
        private void AddGanttTaskLabels(C1Chart chart, ChartDataSeriesCollection cdsc)
        {
            ChartLabels cl = chart.ChartLabels;

            cl.DefaultLabelStyle.BackColor           = Color.Transparent;
            cl.DefaultLabelStyle.GradientStyle       = GradientStyleEnum.None;
            cl.DefaultLabelStyle.ForeColor           = Color.Azure;
            cl.DefaultLabelStyle.HorizontalAlignment = AlignHorzEnum.Far;

            C1.Win.C1Chart.LabelsCollection clc = cl.LabelsCollection;
            clc.Clear();

            int slen = cdsc.Count;

            for (int s = 0; s < cdsc.Count; s++)
            {
                ChartDataSeries cds = cdsc[s];
                for (int p = 0; p < cds.Length; p++)
                {
                    C1.Win.C1Chart.Label lab   = clc.AddNewLabel();
                    DateTime             start = (DateTime)cds.Y[p];
                    DateTime             end   = (DateTime)cds.Y1[p];
                    lab.Text         = start.ToString("ddMMM") + "-" + end.ToString("ddMMM");
                    lab.AttachMethod = AttachMethodEnum.DataIndex;
                    lab.AttachMethodData.GroupIndex  = 0;
                    lab.AttachMethodData.SeriesIndex = s;
                    lab.AttachMethodData.PointIndex  = p;
                    lab.Compass = LabelCompassEnum.West;
                    lab.Offset  = 0;
                    lab.Visible = true;
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Populates the data for the chart
        /// </summary>
        /// <param name="chart"></param>
        /// <param name="inverted"></param>
        /// <returns></returns>
        C1Chart PopulateDataInChart(C1Chart chart,bool inverted)
        {
            double[] x = new double[1000];
               double[] y = new double[1000];
               for (int i = 0; i < 1000; i++)
               {
               x[i] = i; y[i] = 100 * Math.Sin(0.1 * i);
               }
               if (inverted)
               chart.Data.Children.Add(
                 new XYDataSeries()
                 {
                     ConnectionStroke = new SolidColorBrush(Colors.Red),
                     XValuesSource = y,
                     ValuesSource = x
                 });
               else
               chart.Data.Children.Add(
                 new XYDataSeries()
                 {
                     ConnectionStroke = new SolidColorBrush(Colors.Blue),
                     XValuesSource = x,
                     ValuesSource = y
                 });

               return chart;
        }
Esempio n. 12
0
        /// <summary>
        /// Populates the data for the chart
        /// </summary>
        /// <param name="chart"></param>
        /// <param name="inverted"></param>
        /// <returns></returns>
        C1Chart PopulateDataInChart(C1Chart chart, bool inverted)
        {
            double[] x = new double[1000];
            double[] y = new double[1000];
            for (int i = 0; i < 1000; i++)
            {
                x[i] = i; y[i] = 100 * Math.Sin(0.1 * i);
            }
            if (inverted)
            {
                chart.Data.Children.Add(
                    new XYDataSeries()
                {
                    ConnectionStroke = new SolidColorBrush(Colors.Red),
                    XValuesSource    = y,
                    ValuesSource     = x
                });
            }
            else
            {
                chart.Data.Children.Add(
                    new XYDataSeries()
                {
                    ConnectionStroke = new SolidColorBrush(Colors.Blue),
                    XValuesSource    = x,
                    ValuesSource     = y
                });
            }

            return(chart);
        }
Esempio n. 13
0
        public void Create(C1Chart chart, IDataSeries ds, int nser, int npts)
        {
            IDataSeries[] dss = new IDataSeries[nser];
              for (int i = 0; i < nser; i++)
            dss[i] = ds;

              Create(chart, dss, npts);
        }
Esempio n. 14
0
        internal override void UpdateAttachPoint(C1Chart chart, Point offset)
        {
            var prect = chart.View.PlotRect;

              DataSeries ds = Series;

              if (ds == null)
              {
            var series = chart.Data.Children;
            if (SeriesIndex >= series.Count)
              return;
            ds = series[SeriesIndex];
              }

              int npts = GetNumberOfPoints(ds);

              // negative means offset from the end
              if (PointIndex < 0)
            PointIndex = npts + PointIndex;

              if (PointIndex < 0 || PointIndex >= npts)
            return;

              Point pt = new Point(double.NaN, double.NaN);

              if (Series == null)
              {
            pt = DataIndexToPoint(chart, SeriesIndex, PointIndex);
            pt.X -= offset.X;
            pt.Y -= offset.Y;
              }
              else
              {
            var vals = ((IDataSeriesInfo)ds).GetValues();
            if (vals != null)
            {
              var x = vals.GetLength(0) >= 2 ? vals[1, PointIndex] : PointIndex;
              var y = vals[0, PointIndex];

              pt = PointFromData(chart, new Point(x, y), ds.AxisX, ds.AxisY, offset);
            }
              }

              if (double.IsNaN(pt.X) || double.IsNaN(pt.Y))
            return;

              if (AttachPoint.X != 0 && AttachPoint.Y != 0)
              {
            var dx = Canvas.GetLeft(this) - AttachPoint.X;
            var dy = Canvas.GetTop(this) - AttachPoint.Y;
            Canvas.SetLeft(this, pt.X + dx);
            Canvas.SetTop(this, pt.Y + dy);
              }
              else
            SetPosition(pt, Offset);

              AttachPoint = pt;
        }
Esempio n. 15
0
 /// <summary>
 /// Populates the chart data and the axes
 /// </summary>
 /// <param name="chart"></param>
 /// <param name="template">Empty template for chart</param>
 /// <param name="inverted"></param>
 internal void DrawAxisChart(C1Chart chart,DataTemplate template, bool inverted = false)
 {
     chart.ChartType = ChartType.Line;
        PopulateDataInChart(chart, inverted);
        chart.View.AxisX.AnnoTemplate = template;
        chart.View.AxisY.AnnoTemplate = template;
        chart.View.AxisX.MajorTickHeight = chart.View.AxisX.MinorTickHeight = 0;
        chart.View.AxisY.MajorTickHeight = chart.View.AxisY.MinorTickHeight = 0;
 }
Esempio n. 16
0
 /// <summary>
 /// Populates the chart data and the axes
 /// </summary>
 /// <param name="chart"></param>
 /// <param name="template">Empty template for chart</param>
 /// <param name="inverted"></param>
 internal void DrawAxisChart(C1Chart chart, DataTemplate template, bool inverted = false)
 {
     chart.ChartType = ChartType.Line;
     PopulateDataInChart(chart, inverted);
     chart.View.AxisX.AnnoTemplate    = template;
     chart.View.AxisY.AnnoTemplate    = template;
     chart.View.AxisX.MajorTickHeight = chart.View.AxisX.MinorTickHeight = 0;
     chart.View.AxisY.MajorTickHeight = chart.View.AxisY.MinorTickHeight = 0;
 }
Esempio n. 17
0
        public void Create(C1Chart chart, IDataSeries ds, int nser, int npts)
        {
            IDataSeries[] dss = new IDataSeries[nser];
            for (int i = 0; i < nser; i++)
            {
                dss[i] = ds;
            }

            Create(chart, dss, npts);
        }
        private void c1Chart1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            C1Chart    chart = (C1Chart)sender;
            int        g = 0, s = -1, p = -1, d = -1;
            ChartGroup grp = chart.ChartGroups[g];

            ChartRegionEnum region = chart.ChartRegionFromCoord(e.X, e.Y);

            string footerText = "Nowhere";

            if (region.Equals(ChartRegionEnum.Legend))
            {
                // if in the legend, check for the series and update
                // the footerText as appropriate
                Legend leg = chart.Legend;
                if (leg.SeriesFromCoord(e.X, e.Y, ref g, ref s))
                {
                    if (s >= 0)
                    {
                        footerText = string.Format("Series {0}", s);
                    }
                }
            }
            else
            {
                // if it's close enough check for the series and update
                // the footerText as appropriate
                CoordinateFocusEnum focus = CoordinateFocusEnum.XandYCoord;
                bool stacked = grp.Stacked;
                int  minDist = 5;

                if (radioBar.Checked && !stacked)
                {
                    // special case where X focus is more appropriate
                    focus   = CoordinateFocusEnum.XCoord;
                    minDist = 0;
                }
                else if (radioPie.Checked || (radioBar.Checked && stacked))
                {
                    // special case where minimum distance of 0 is more
                    // appropriate.
                    minDist = 0;
                }

                if (grp.CoordToDataIndex(e.X, e.Y, focus, ref s, ref p, ref d))
                {
                    if (s >= 0 && p >= 0 && d <= minDist)
                    {
                        footerText = string.Format("Index({0},{1})", s, p);
                    }
                }
            }

            chart.Footer.Text = footerText;
        }
Esempio n. 19
0
        /// <summary>
        /// Creates an instance of SeriesAxis.
        /// </summary>
        /// <param name="chart"></param>
        /// <param name="series"></param>
        public SeriesAxis1(C1Chart chart, DataSeries series)
        {
            _chart = chart;
            _series = series;

            if (_series != null)
                Name = _series.AxisY;

            AnnoCreated += new AnnoCreatedEventHandler(SeriesAxis_AnnoCreated);
            MajorGridStroke = null;
        }
        public static void CreateData(C1Chart chart)
        {
            chart.BeginUpdate();

            chart.Data.Children.Clear();

            var ds = CreateDataSeries(100, false);

            chart.Data.Children.Add(ds);
            chart.EndUpdate();
        }
Esempio n. 21
0
        public override void ZoomBounds(System.Windows.Forms.Control control, ZoomBoundsInfo infos)
        {
            C1Chart chart = control as C1Chart;

            ZoomChartGroups(infos, chart.ChartGroups);
            ZoomChartArea(infos, chart.ChartArea);
            ZoomTitle(infos, chart.Header);
            ZoomTitle(infos, chart.Footer);
            ZoomLegend(infos, chart.Legend);
            ZoomChartLabels(infos, chart.ChartLabels);
            base.ZoomBounds(control, infos);
        }
Esempio n. 22
0
        /// <summary>
        /// Creates an instance of SeriesAxis.
        /// </summary>
        /// <param name="chart"></param>
        /// <param name="series"></param>
        public SeriesAxis1(C1Chart chart, DataSeries series)
        {
            _chart  = chart;
            _series = series;

            if (_series != null)
            {
                Name = _series.AxisY;
            }

            AnnoCreated    += new AnnoCreatedEventHandler(SeriesAxis_AnnoCreated);
            MajorGridStroke = null;
        }
Esempio n. 23
0
        /// <summary>
        /// Creates an instance of YSeriesAxis.
        /// </summary>
        /// <param name="chart"></param>
        /// <param name="series"></param>
        /// <param name="position"></param>
        public YSeriesAxis(C1Chart chart, DataSeries series, AxisPosition position)
            : base(chart, series)
        {
            AxisType = AxisType.Y;
            Position = position;

            if ((position & AxisPosition.Far) > 0)
                AnnoAngle = 90;
            else
                AnnoAngle = -90;

            MinorTickHeight = 0;
        }
Esempio n. 24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="chart"></param>
        public GraphicProperty(C1Chart chart, TextBlock tby1, TextBlock tby2, TextBlock tbCaption)
        {
            this.chart = chart;

            this.tby1      = tby1;
            this.tby2      = tby2;
            this.tbCaption = tbCaption;

            y1 = chart.View.AxisY;
            y2 = chart.View.Axes["y2"];
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }
Esempio n. 25
0
        public ChartState(C1Chart chart)
        {
            PlotRect = chart.View.PlotRect;

              foreach (var ax in chart.View.Axes)
              {
            _list.Add(ax.Min);
            _list.Add(ax.Max);
            _list.Add(ax.ActualMin);
            _list.Add(ax.ActualMax);
            _list.Add(ax.Scale);
            _list.Add(ax.Value);
              }
        }
        private void c1Chart1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            C1Chart chart = (C1Chart)sender;

            if (e.Button.Equals(MouseButtons.Left))
            {
                int             g = -1, s = -1, p = -1, d = -1;
                ChartGroup      grp = chart.ChartGroups[0];
                ChartDataSeries ser = null;

                ChartRegionEnum region = chart.ChartRegionFromCoord(e.X, e.Y);
                if (region.Equals(ChartRegionEnum.Legend))
                {
                    if (chart.Legend.SeriesFromCoord(e.X, e.Y, ref g, ref s))
                    {
                        ser = grp.ChartData.SeriesList[s];
                        if (ser.Display.Equals(SeriesDisplayEnum.Show))
                        {
                            ser.Display = SeriesDisplayEnum.Hide;
                        }
                        else
                        {
                            ser.Display = SeriesDisplayEnum.Show;
                        }
                    }
                    return;
                }

                if (grp.CoordToDataIndex(e.X, e.Y, CoordinateFocusEnum.XandYCoord,
                                         ref s, ref p, ref d))
                {
                    if (d == 0 && s >= 0 && p >= 0)
                    {
                        ser = grp.ChartData.SeriesList[s];
                        int offset = ser.Offset;
                        if (offset == 0)
                        {
                            offset = 40;
                        }
                        else
                        {
                            offset = 0;
                        }
                        ser.Offset = offset;

                        SetTextBoxSliceOffsetValue(s, offset);
                    }
                }
            }
        }
Esempio n. 27
0
        public ChartState(C1Chart chart)
        {
            PlotRect = chart.View.PlotRect;

            foreach (var ax in chart.View.Axes)
            {
                _list.Add(ax.Min);
                _list.Add(ax.Max);
                _list.Add(ax.ActualMin);
                _list.Add(ax.ActualMax);
                _list.Add(ax.Scale);
                _list.Add(ax.Value);
            }
        }
 public void ApplyOptions(C1Chart chart)
 {
     if (_limits)
     {
         chart.ChartArea.AxisX.SetMinMax(_xmin, _xmax);
         chart.ChartArea.AxisY.SetMinMax(_ymin, _ymax);
     }
     else
     {
         chart.ChartArea.AxisX.AutoMax = true;
         chart.ChartArea.AxisX.AutoMin = true;
         chart.ChartArea.AxisY.AutoMax = true;
         chart.ChartArea.AxisY.AutoMin = true;
     }
 }
 /// <summary>
 /// Resets the chart localizations to the default state for the
 /// specified chart.  This removes previous localizations and
 /// frees all memory associated with the localizations.
 /// </summary>
 /// <param name="objChart"></param>
 private void resetLocalizations(object objChart)
 {
     // passing null to any of the LoadLocalization overload
     // clears any existing localizations previously loaded.
     if (objChart is C1Chart)
     {
         C1Chart chart = objChart as C1Chart;
         chart.LoadLocalizations((Stream)null);
     }
     else if (objChart is C1Chart3D)
     {
         C1Chart3D chart = objChart as C1Chart3D;
         chart.LoadLocalizations((Stream)null);
     }
 }
Esempio n. 30
0
        public SeriesData(C1Chart chart, ImageList images)
        {
            ChartDataSeriesCollection sc = chart.ChartGroups[0].ChartData.SeriesList;

            m_sers = (SeriesInfo[])Array.CreateInstance(typeof(SeriesInfo), sc.Count);
            for (int i = 0; i < sc.Count; i++)
            {
                Image img = null;
                if (i < images.Images.Count)
                {
                    img = images.Images[i];
                }
                m_sers[i] = new SeriesInfo(sc[i], img);
            }
        }
        /// <summary>
        /// Creates a form and show the localization XML for the specified chart.
        ///
        /// The localization XML is saved to a byte array for easy conversion to
        /// text.  Note that the first bytes of the array may be byte encodings.
        ///
        /// The form is sizeable.
        /// </summary>
        /// <param name="objChart"></param>
        private void showLocalizations(object objChart)
        {
            string title = " string localizations.";

            byte[] ChartLocalizationBytes = null;

            if (objChart is C1Chart)
            {
                C1Chart chart = objChart as C1Chart;
                chart.SaveLocalizations(out ChartLocalizationBytes);
                title = chart.Name + title;
            }
            else if (objChart is C1Chart3D)
            {
                C1Chart3D chart = objChart as C1Chart3D;
                chart.SaveLocalizations(out ChartLocalizationBytes);
                title = chart.Name + title;
            }
            else
            {
                MessageBox.Show("Object specified is not supported.");
                return;
            }

            string ChartLocalizationString = Encoding.UTF8.GetString(ChartLocalizationBytes);

            Form    frm = new Form();
            TextBox tb  = new TextBox();

            frm.Text            = title;
            frm.Size            = this.Size;
            frm.WindowState     = FormWindowState.Normal;
            frm.FormBorderStyle = FormBorderStyle.Sizable;

            frm.Controls.Add(tb);
            tb.Dock            = DockStyle.Fill;
            tb.Multiline       = true;
            tb.ReadOnly        = true;
            tb.ScrollBars      = ScrollBars.Both;
            tb.Text            = ChartLocalizationString;
            tb.SelectionStart  = 0;
            tb.SelectionLength = 0;
            tb.Visible         = true;

            frm.Show();
        }
        /// <summary>
        /// Creates an instance of YSeriesAxis.
        /// </summary>
        /// <param name="chart"></param>
        /// <param name="series"></param>
        /// <param name="position"></param>
        public YSeriesAxis(C1Chart chart, DataSeries series, AxisPosition position)
            : base(chart, series)
        {
            AxisType = AxisType.Y;
            Position = position;

            if ((position & AxisPosition.Far) > 0)
            {
                AnnoAngle = 90;
            }
            else
            {
                AnnoAngle = -90;
            }

            MinorTickHeight = 0;
        }
Esempio n. 33
0
        /// <summary>
        /// Performs coordinate conversion from data to chart view.
        /// </summary>
        /// <param name="chart"></param>
        /// <param name="point"></param>
        /// <param name="axisX"></param>
        /// <param name="axisY"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        protected static Point PointFromData(C1Chart chart, Point point, string axisX, string axisY, Point offset)
        {
            var    prect = chart.View.PlotRect;
            double x     = double.NaN;
            bool   hasx  = false;

            if (!string.IsNullOrEmpty(axisX))
            {
                var axx = chart.View.Axes[axisX];
                if (axx != null)
                {
                    var ptx = axx.PointFromData(point);
                    x = ptx.X - prect.X; hasx = true;
                }
            }

            double y    = double.NaN;
            bool   hasy = false;

            if (!string.IsNullOrEmpty(axisY))
            {
                var axy = chart.View.Axes[axisY];
                if (axy != null)
                {
                    var pty = axy.PointFromData(point);
                    y = pty.Y - prect.Y; hasy = true;
                }
            }

            var pt = chart.View.PointFromData(point);

            pt.X -= offset.X;
            pt.Y -= offset.Y;

            if (hasx)
            {
                pt.X = x;
            }
            if (hasy)
            {
                pt.Y = y;
            }

            return(pt);
        }
Esempio n. 34
0
        private void SetupStatisticsInfo(C1Chart chart)
        {
            // obtain the temperature statistics from the chart series, and report
            // them through the textbox.
            TextBox tb = txtStatistics;
            ChartDataSeriesCollection cdsc = chart.ChartGroups[0].ChartData.SeriesList;

            foreach (ChartDataSeries cds in cdsc)
            {
                double mean  = cds.Y.Statistics.Mean;
                double meanC = (mean - 32) * 5.0 / 9.0;

                double sd  = cds.Y.Statistics.StdDev;
                double sdC = sd * 5.0 / 9.0;

                tb.Text += cds.Label + "\r\n";
                tb.Text += "   Mean:   " + mean.ToString("0.0") + "F (" + meanC.ToString("0.0") + "C)\r\n";
                tb.Text += "   StdDev: " + sd.ToString("0.00") + "F (" + sdC.ToString("0.00") + "C)\r\n\r\n";
            }
        }
Esempio n. 35
0
        /// <summary>
        /// 챠트를 이미지로 저장한다.
        /// </summary>
        /// <param name="chart"></param>
        public static void Chart_SaveAsImage(C1Chart chart)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = "Bitmap (*.bmp)|*.bmp|"
                         + "EMF Enhanced Metafile Format (*.emf)|*.emf|"
                         + "Graphics Interchange Format (*.gif)|*.gif|"
                         + "Joint Photographic Experts Group (*.jpg)|*.jpg|"
                         + "W3C Portable Network Graphics (*.png)|*.png";
            sfd.DefaultExt       = "bmp";
            sfd.FileName         = "image1";
            sfd.OverwritePrompt  = true;
            sfd.CheckPathExists  = true;
            sfd.RestoreDirectory = false;
            sfd.ValidateNames    = true;

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                chart.SaveImage(sfd.FileName, getImageFormatFromDlg(sfd.FilterIndex), getSize());
            }
        }
        private void _btnInsertChart_Click(object sender, RoutedEventArgs e)
        {
            if (Math.Abs(_flex.Selection.RightColumn - _flex.Selection.LeftColumn) > 0 &&
                Math.Abs(_flex.Selection.BottomRow - _flex.Selection.TopRow) > 0 &&
                _flex.Selection.IsValid)
            {
                C1Chart c1Chart1 = new C1Chart();
                c1Chart1.Data.Children.Clear();
                for (int row = _flex.Selection.TopRow; row <= _flex.Selection.BottomRow; row++)
                {
                    List <double> datas = new List <double>();
                    for (int col = _flex.Selection.LeftColumn; col <= _flex.Selection.RightColumn; col++)
                    {
                        object value = _flex[row, col];
                        if (value != null && value.GetType().IsNumeric())
                        {
                            double cellValue = (double)value;
                            datas.Add(cellValue);
                        }
                    }
                    // create single series for product price
                    DataSeries ds = new DataSeries();
                    //set data
                    ds.ValuesSource = datas;
                    // add series to the chart
                    c1Chart1.Data.Children.Add(ds);
                }

                // add item names
                //c1Chart1.Data.ItemNames = ProductNames;
                // Set chart type
                c1Chart1.ChartType = ChartType.Bar;
                _flex.InsertChart(c1Chart1);
            }
            else
            {
                MessageBox.Show("Please select more data");
            }
        }
Esempio n. 37
0
        public virtual void Create(C1Chart chart, IDataSeries[] dss, int npts)
        {
            Reset(chart);

            IEnumerable x = null;

            for (int i = 0; i < dss.Length; i++)
            {
                DataSeries ds = null;
                if (i < chart.Data.Children.Count)
                {
                    ds = (DataSeries)chart.Data.Children[i];
                    dss[i].Update(ds, npts);
                }
                else
                {
                    ds = dss[i].Create(npts);
                }

                XYDataSeries xds = ds as XYDataSeries;
                if (xds != null)
                {
                    if (x == null)
                    {
                        x = xds.XValuesSource;
                    }
                    else
                    {
                        xds.XValuesSource = x;
                    }
                }

                if (!chart.Data.Children.Contains(ds))
                {
                    chart.Data.Children.Add(ds);
                }
            }
        }
        private void C1Chart_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            C1Chart chart = (C1Chart)sender;

            chart.Data.Children.Add(new DataSeries()
            {
                Label = "Series1", ValuesSource = new double[] { 3, 2, 7, 4, 8 }
            });

            if (chart.ChartType != ChartType.Pie)
            {
                chart.Data.Children.Add(new DataSeries()
                {
                    Label = "Series2", ValuesSource = new double[] { 1, 2, 3, 4, 6 }
                });
                chart.Data.Children.Add(new DataSeries()
                {
                    Label = "Series3", ValuesSource = new double[] { 0, 1, 6, 2, 3 }
                });
            }

            chart.Loaded -= new RoutedEventHandler(C1Chart_Loaded);
        }
        /// <summary>
        /// Creates a form and adds a PropertyGrid connected to the specified chart.
        /// The localizations of the Property Descriptions can be seen.
        ///
        /// Special Note: Once a control property description has been
        /// retrieved, it does not change for the application.	This is a
        /// behavior of the .NET PropertyDescriptor.
        ///
        /// The form is sizeable.
        /// </summary>
        /// <param name="objChart"></param>
        private void showPropertyGrids(object objChart)
        {
            string title = " Property Grid.";

            Form         frm = new Form();
            PropertyGrid pg  = new PropertyGrid();

            if (objChart is C1Chart)
            {
                C1Chart chart = objChart as C1Chart;
                pg.SelectedObject = chart;
                title             = chart.Name + title;
            }
            else if (objChart is C1Chart3D)
            {
                C1Chart3D chart = objChart as C1Chart3D;
                pg.SelectedObject = chart;
                title             = chart.Name + title;
            }
            else
            {
                MessageBox.Show("Object specified is not supported.");
                return;
            }

            frm.Text            = title;
            frm.Size            = new Size(300, 400);
            frm.WindowState     = FormWindowState.Normal;
            frm.FormBorderStyle = FormBorderStyle.Sizable;

            frm.Controls.Add(pg);
            pg.Dock        = DockStyle.Fill;
            pg.HelpVisible = true;

            frm.Show();
        }
Esempio n. 40
0
 /// <summary>
 /// Populates C1WPFChart with created data
 /// </summary>
 /// <param name="chart">C1WPFChart</param>
 internal void DrawChart(C1Chart chart, bool inverted = false)
 {
     chart.ChartType = ChartType.Line;
        PopulateDataInChart(chart, inverted);
 }
Esempio n. 41
0
        Point DataIndexToPoint(C1Chart chart, int seriesIndex, int pointIndex)
        {
            if (chart.ChartType.ToString().StartsWith("Pie"))
              {
            var slices = chart.FindChildren<PieSlice>();

            foreach (var slice in slices)
            {
              if (slice.DataPoint.SeriesIndex == seriesIndex && slice.DataPoint.PointIndex == pointIndex)
              {
            plotCenter = slice.PieCenter;
            var geom = slice.RenderedGeometry as PathGeometry;
            var arc = geom.Figures[0].Segments[1] as ArcSegment;

            var angle = slice.Angle/180*Math.PI;
            return new Point(slice.PieCenter.X + arc.Size.Width*Math.Cos(angle),
              slice.PieCenter.Y + arc.Size.Height * Math.Sin(angle));
              }
            }
            return new Point();
              }
              else
            return chart.View.DataIndexToPoint(seriesIndex, pointIndex);
        }
Esempio n. 42
0
 protected void Reset(C1Chart chart)
 {
     chart.Data.Renderer = new Renderer2D();
 }
Esempio n. 43
0
 private void BindSeries(C1Chart c1c, int series, object dataSource, string field)
 {
     BindSeries(c1c, series, dataSource, field, null);
 }
Esempio n. 44
0
 /// <summary>
 /// Populates C1WPFChart with created data
 /// </summary>
 /// <param name="chart">C1WPFChart</param>
 internal void DrawChart(C1Chart chart, bool inverted = false)
 {
     chart.ChartType = ChartType.Line;
     PopulateDataInChart(chart, inverted);
 }
        // ** utilities
        void CreateDataSeries(C1Chart chart, WeatherData[] data)
        {
            chart.Data.Children.Clear();

            #if DataBinding
              chart.Data.ItemsSource = data;
            #else
              int len = data.Length;
              DateTime[] days = new DateTime[len];
              double[] tmin = new double[len];
              double[] tmax = new double[len];
              double[] tavg = new double[len];
              for (int i = 0; i < len; i++)
              {
            days[i] = data[i].DateTime;
            tmin[i] = data[i].TMin;
            tmax[i] = data[i].TMax;
            tavg[i] = data[i].TAvg;
              }
            #endif

              XYDataSeries ds = new XYDataSeries(); ds.Label = "Minimum";
            #if DataBinding
              ds.ValueBinding = new Binding("TMin");
              ds.XValueBinding = new Binding("DateTime");
            #else
              ds.XValuesSource = days;
              ds.ValuesSource = tmin;
            #endif
              ds.ConnectionStroke = new SolidColorBrush(Colors.Blue);
              chart.Data.Children.Add(ds);

              ds = new XYDataSeries(); ds.Label = "Maximum";
            #if DataBinding
              ds.ValueBinding = new Binding("TMax");
              ds.XValueBinding = new Binding("DateTime");
            #else
              ds.XValuesSource = days;
              ds.ValuesSource = tmax;
            #endif
              ds.ConnectionStroke = new SolidColorBrush(Colors.Red);
              chart.Data.Children.Add(ds);

              ds = new XYDataSeries(); ds.Label = "Average";
            #if DataBinding
              ds.ValueBinding = new Binding("TAvg");
              ds.XValueBinding = new Binding("DateTime");
            #else
              ds.XValuesSource = days;
              ds.ValuesSource = tavg;
            #endif
              chart.Data.Children.Add(ds);

              foreach (DataSeries ser in chart.Data.Children)
            ser.ConnectionStrokeThickness = 1;

              chart.View.AxisX.IsTime = true;
              chart.View.AxisX.AnnoPosition = AnnoPosition.Near;
        }
Esempio n. 46
0
        public static void CreateData(C1Chart chart)
        {
            chart.BeginUpdate();

              chart.Data.Children.Clear();

              var ds = CreateDataSeries(100, false);
              chart.Data.Children.Add(ds);
              chart.EndUpdate();
        }
Esempio n. 47
0
        /// <summary>
        /// Performs coordinate conversion from data to chart view.
        /// </summary>
        /// <param name="chart"></param>
        /// <param name="point"></param>
        /// <param name="axisX"></param>
        /// <param name="axisY"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        protected static Point PointFromData(C1Chart chart, Point point, string axisX, string axisY, Point offset)
        {
            var prect = chart.View.PlotRect;
              double x = double.NaN;
              bool hasx = false;
              if (!string.IsNullOrEmpty(axisX))
              {
            var axx = chart.View.Axes[axisX];
            if (axx != null)
            {
              var ptx = axx.PointFromData(point);
              x = ptx.X - prect.X; hasx = true;
            }
              }

              double y = double.NaN;
              bool hasy = false;
              if (!string.IsNullOrEmpty(axisY))
              {
            var axy = chart.View.Axes[axisY];
            if (axy != null)
            {
              var pty = axy.PointFromData(point);
              y = pty.Y - prect.Y; hasy = true;
            }
              }

              var pt = chart.View.PointFromData(point);

              pt.X -= offset.X;
              pt.Y -= offset.Y;

              if (hasx)
            pt.X = x;
              if (hasy)
            pt.Y = y;

              return pt;
        }
Esempio n. 48
0
 internal abstract void UpdateAttachPoint(C1Chart chart, Point offset);