示例#1
0
 public DXCheckItem(LegendAlignmentHorizontal alignment, string caption, ChartControl chartControl)
     : base(chartControl, caption)
 {
     this.alignment = alignment;
     Checked        = this.chartControl.Legend.AlignmentHorizontal == this.alignment;
 }
示例#2
0
        public void CreateLineplot(DataTable mydt)
        {
            _coloroverride = -1;
            string seriesby = _settings.seriesby;
            string colorsby = _settings.colorvar;
            Color  myseriescolor;

            DataTable dataxy_all = DataTableExtensions.Data_SelectColumnXY(mydt, _settings.xaxisvar, _settings.yaxisvar, seriesby, colorsby);


            List <string> series_levels = dataxy_all.AsEnumerable().Select(x => x.Field <string>("seriesby")).Distinct().ToList();
            List <string> colors_levels = dataxy_all.AsEnumerable().Select(x => x.Field <string>("colorsby")).Distinct().ToList();

            colors_levels.Sort();

            _colorLevels = colors_levels;             //use this to create a manual legend later if needed


            List <string> seriesIDs = new List <string>();

            if (seriesby == "id")
            {
                seriesIDs = dataxy_all.AsEnumerable().Select(x => x.Field <string>("id")).Distinct().ToList();
            }
            else
            {
                seriesIDs = dataxy_all.AsEnumerable().Select(x => x.Field <string>("seriesby")).Distinct().ToList();
            }


            int _nall = dataxy_all.Rows.Count;

            if (_nall > 0)
            {
                List <Series> list_o_series = new List <Series>();

                //foreach (string s in seriesIDs)
                for (int s = 0; s < seriesIDs.Count; s++)
                {
                    for (int s_color = 0; s_color < colors_levels.Count; s_color++)
                    {
                        dataxy_all.DefaultView.Sort             = "seriesby ASC, colorsby ASC, x ASC";
                        dataxy_all.DefaultView.ApplyDefaultSort = true;
                        DataView vw = dataxy_all.AsDataView();

                        string rowfilter = (seriesby == "id") ?
                                           String.Format("{0}='{1}' and colorsby='{2}'", seriesby, seriesIDs[s], colors_levels[s_color]) :
                                           String.Format("{0}='{1}' and colorsby='{2}'", "seriesby", seriesIDs[s], colors_levels[s_color]);

                        //string rowfilter = (seriesby == "id") ?
                        //			String.Format("{0}='{1}'", seriesby, seriesIDs[s]) :
                        //			String.Format("{0}='{1}'", "seriesby", seriesIDs[s]);

                        vw.RowFilter = rowfilter;
                        //vw.Sort = String.Format("{0} {1}", "x", "ASC");  //sort by the x variable
                        //vw.ApplyDefaultSort = true;

                        DataTable dataxy = vw.ToTable();

                        dataxy.DefaultView.Sort             = "x ASC";
                        dataxy.DefaultView.ApplyDefaultSort = true;

                        n = dataxy.Rows.Count;

                        if (n > 0)
                        {
                            string        current_colorlevel = dataxy.AsEnumerable().Select(f => f.Field <string>("colorsby")).Min().ToString();
                            List <string> series_colors      = dataxy.AsEnumerable().Select(f => f.Field <string>("colorsby")).ToList();


                            //Switch to alternate geom if needed
                            if (_settings.vars_for_altgeom.Contains(current_colorlevel))
                            {
                                _settings.activegeom = _settings.altgeom;
                            }
                            else
                            {
                                _settings.activegeom = _settings.geom;
                            }


                            int colorindex = 0;

                            //Get the correct color
                            if (colorsby != "none")
                            {
                                for (int c = 0; c < colors_levels.Count; c++)
                                {
                                    if (current_colorlevel == colors_levels[c])
                                    {
                                        colorindex = c;
                                    }
                                }
                            }
                            myseriescolor = _settings.color(colorindex % 15);

                            if (_coloroverride >= 0)
                            {
                                myseriescolor = _settings.color(_coloroverride % 15);
                            }


                            SeriesPoint[] seriesPoints = CreateSeriesPoints(dataxy, colorsby, colors_levels, series_colors, colorindex, myseriescolor);
                            //TOFIX SeriesPoint[] seriesPoints = new DxSeriesPoints(dataxy, "x", "y", colorsby, colors_levels, series_colors, colorindex, myseriescolor);


                            Series series = new Series();

                            SideBySideBarSeriesView barSeriesView   = new SideBySideBarSeriesView();
                            LineSeriesView          lineSeriesView  = new LineSeriesView();
                            PointSeriesView         pointSeriesView = new PointSeriesView();

                            if (_settings.activegeom == LineplotGeom.Bar)
                            {
                                //barSeriesView = new SideBySideBarSeriesView() ;
                            }
                            else if (_settings.activegeom == LineplotGeom.Line)
                            {
                                //lineSeriesView = new LineSeriesView();
                                lineSeriesView.LineMarkerOptions.FillStyle.FillMode = FillMode.Solid;
                                lineSeriesView.LineMarkerOptions.Kind = _markers[s % _markers.Count];
                            }
                            else
                            {
                                pointSeriesView.PointMarkerOptions.FillStyle.FillMode = FillMode.Solid;
                                MarkerKind mymarker = new MarkerKind();

                                if (_settings.activegeom == LineplotGeom.Circle)
                                {
                                    mymarker = MarkerKind.Circle;
                                }
                                if (_settings.activegeom == LineplotGeom.Square)
                                {
                                    mymarker = MarkerKind.Square;
                                }
                                if (_settings.activegeom == LineplotGeom.Cross)
                                {
                                    mymarker = MarkerKind.Cross;
                                }
                                if (_settings.activegeom == LineplotGeom.Star)
                                {
                                    mymarker = MarkerKind.Star;
                                }

                                pointSeriesView.PointMarkerOptions.Kind = mymarker;
                                pointSeriesView.PointMarkerOptions.Size = _settings.markersize;

                                if (_settings.activegeom == LineplotGeom.Star)
                                {
                                    pointSeriesView.PointMarkerOptions.StarPointCount = 6;
                                }
                            }



                            if (_settings.xaxis_is_date)
                            {
                                this.xydiagram.AxisX.DateTimeScaleOptions.ScaleMode   = ScaleMode.Continuous;
                                this.xydiagram.AxisX.DateTimeScaleOptions.MeasureUnit = DateTimeMeasureUnit.Month;
                                this.xydiagram.AxisX.Label.TextPattern = "{A:dd-MMM-yy}";
                                series.ToolTipPointPattern             = "x={A:dd-MMM-yy} y={V:F2} {HINT}";
                            }
                            else
                            {
                                series.ToolTipPointPattern = "x={A:F2} y={V:F2} {HINT}";
                            }


                            ToolTipRelativePosition pos = new ToolTipRelativePosition();
                            pos.OffsetX = -10;
                            pos.OffsetY = -10;
                            chart.ToolTipOptions.ToolTipPosition = pos;

                            if (_settings.activegeom == LineplotGeom.Bar)
                            {
                                series.View = barSeriesView;
                            }
                            else if (_settings.activegeom == LineplotGeom.Line)
                            {
                                series.View = lineSeriesView;
                            }
                            else
                            {
                                series.View = pointSeriesView;
                            }

                            series.Points.AddRange(seriesPoints);

                            list_o_series.Add(series);
                        }
                    }
                }

                //Add the series to the chart
                int max_pts = list_o_series.Select(s => s.Points.Count).Max();

                foreach (Series s in list_o_series)
                {
                    //first add those with the max number of points
                    if (s.Points.Count == max_pts)
                    {
                        chart.Series.Add(s);
                    }
                }
                foreach (Series s in list_o_series)
                {
                    //then add those with fewer points
                    if (s.Points.Count != max_pts)
                    {
                        chart.Series.Add(s);
                    }
                }


                // consider adding N=??, intrcpt=, slope=
                string mytitle       = "";
                string mainTitleText = String.Format("{0}", mytitle);                 //, seriesPoints.Count());

                chart.Width  = _settings.W;
                chart.Height = _settings.H;

                this.AddTitles(mainTitleText, "", _settings.xaxisvar, _settings.yaxisvar);

                chart.BorderOptions.Color = Color.White;

                chart.CustomDrawSeriesPoint += Lineplot_TransparentPoint;
                chart.CustomDrawSeries      += Lineplot_TransparentLine;

                //chart.CustomCallback += _dxcharts.Mychart_CustomCallback;

                chart.ToolTipEnabled = DevExpress.Utils.DefaultBoolean.True;
                chart.ToolTipOptions.ShowForSeries = true;

                chart.CrosshairEnabled = DevExpress.Utils.DefaultBoolean.False;

                if (colorsby != "none")
                {
                    for (int lev = 0; lev < colors_levels.Count; lev++)
                    {
                        // Create a new custom item.
                        CustomLegendItem item = new CustomLegendItem();
                        chart.Legend.CustomItems.Add(item);
                        // Specify its text and marker.
                        item.Text = colors_levels[lev];
                        int coloridx = (_coloroverride >= 0) ? _coloroverride : lev;
                        item.MarkerColor = _settings.colors[coloridx % _settings.colors.Count];
                        //item.
                    }
                }



                chart.Legend.Visibility = (_settings.showLegend) ? DevExpress.Utils.DefaultBoolean.True : DevExpress.Utils.DefaultBoolean.False;

                LegendAlignmentHorizontal legend_h = new LegendAlignmentHorizontal();
                LegendAlignmentVertical   legend_v = new LegendAlignmentVertical();

                if (_settings.legend_pos_h == "Right")
                {
                    legend_h = LegendAlignmentHorizontal.Right;
                }
                else if (_settings.legend_pos_h == "RightOutside")
                {
                    legend_h = LegendAlignmentHorizontal.RightOutside;
                }
                else if (_settings.legend_pos_h == "Left")
                {
                    legend_h = LegendAlignmentHorizontal.Left;
                }
                else if (_settings.legend_pos_h == "LeftOutside")
                {
                    legend_h = LegendAlignmentHorizontal.LeftOutside;
                }
                else if (_settings.legend_pos_h == "Center")
                {
                    legend_h = LegendAlignmentHorizontal.Center;
                }

                if (_settings.legend_pos_v == "Top")
                {
                    legend_v = LegendAlignmentVertical.Top;
                }
                else if (_settings.legend_pos_v == "TopOutside")
                {
                    legend_v = LegendAlignmentVertical.TopOutside;
                }
                else if (_settings.legend_pos_v == "Bottom")
                {
                    legend_v = LegendAlignmentVertical.Bottom;
                }
                else if (_settings.legend_pos_v == "BottomOutside")
                {
                    legend_v = LegendAlignmentVertical.BottomOutside;
                }
                else if (_settings.legend_pos_v == "Center")
                {
                    legend_v = LegendAlignmentVertical.Center;
                }



                chart.Legend.AlignmentHorizontal = legend_h;
                chart.Legend.AlignmentVertical   = legend_v;

                // Set a value indicating that both autogenerated and custom items are displayed.
                chart.Legend.ItemVisibilityMode = LegendItemVisibilityMode.AutoGeneratedAndCustom;
            }
            else
            {
                //_emptymsg = String.Format("0 cases for{3}{0}{3}{1} by {2}", mytitle, xvar, yvar, Environment.NewLine);
                //return null;
            }
        }