OXYPlot 图表控件 显示X轴Log分布

  try
            {
                //var thisyearquery = data?.Where(d => Convert.ToDateTime(d.Date).Year == DateTime.Now.Year);
                var Nearly15MonthData = data?.Where(d => Convert.ToDateTime(d.Date) > DateTime.Now.AddMonths(-15)).ToList();

                PlotModel tmp = new PlotModel
                {
                    
                };
                this.PatientYearNumModeSeries = tmp;
                var start = DateTime.Now.AddMonths(-15);
                var end = DateTime.Now.AddMonths(0);
                #region 坐标轴
                //坐标轴X设置
                DateTimeAxis linearAxisX = new DateTimeAxis();
                linearAxisX.MajorGridlineStyle = LineStyle.Solid;
                linearAxisX.MinorGridlineStyle = LineStyle.Dot;
                linearAxisX.Position = AxisPosition.Bottom;
                linearAxisX.Minimum = DateTimeAxis.ToDouble(start.AddMonths(-1));
                linearAxisX.Maximum = DateTimeAxis.ToDouble(end.AddMonths(1));
                //最小间隔一个月
                linearAxisX.MinorIntervalType = DateTimeIntervalType.Months;
                //间隔一个月
                linearAxisX.IntervalType = DateTimeIntervalType.Months;
                linearAxisX.FirstDayOfWeek = DayOfWeek.Monday;
                //linearAxisX.MajorStep = (double)30.1 ;
                //linearAxisX.MinorStep = (double)28;
                linearAxisX.StringFormat = "MMM \nyyyy";
                linearAxisX.Title = "时间";
                tmp.Axes.Add(linearAxisX);
                tmp.PlotAreaBorderThickness = new OxyThickness(1, 0, 0, 1);

                //坐标轴Y设置
                LinearAxis linearAxisY = new LinearAxis();
                linearAxisY.MajorGridlineStyle = LineStyle.Solid;
                linearAxisY.MinorGridlineStyle = LineStyle.Dot;
                //缩放
                linearAxisY.IsZoomEnabled = false;
                //平移
                linearAxisY.IsPanEnabled = false;
                linearAxisY.MinorStep = double.NaN;
                linearAxisY.Title = "人数";

                tmp.Axes.Add(linearAxisY);
                #endregion

                var lineSeries1 = new LineSeries();
                lineSeries1.InterpolationAlgorithm = InterpolationAlgorithms.CanonicalSpline;
                //lineSeries1.MarkerFill = OxyColor.Parse("#304F7D");
                //lineSeries1.MarkerSize = 4;
                //lineSeries1.MarkerStroke = OxyColors.White;
                //lineSeries1.MarkerStrokeThickness = 1.5;
                //lineSeries1.MarkerType = MarkerType.Circle;
                lineSeries1.CanTrackerInterpolatePoints = false;
                lineSeries1.Color = OxyColor.Parse("#304F7D");
                lineSeries1.StrokeThickness = 2;
                lineSeries1.Font = "Microsoft YaHei";
                lineSeries1.FontSize = 16;
                lineSeries1.DataFieldX = "Date";
                lineSeries1.DataFieldY = "Value";
                lineSeries1.TextColor = OxyColor.Parse("#686868");
                var c = lineSeries1.TextColor;
                lineSeries1.TrackerFormatString = "时间:{2:yyyy年MM月}\n人数:{4:0.##}人";
                //是否在没有是实际点的地方显示Tracker 点信息
                lineSeries1.CanTrackerInterpolatePoints = false;
                //lineSeries1.LabelFormatString = "{1}";
                //画曲线主要是需要将线的 InterpolationAlgorithm 属性 设置为 CanonicalSpline 就可变成曲线
                //lineSeries1.InterpolationAlgorithm = InterpolationAlgorithms.CanonicalSpline;
                //var data = await _dictionaryItemService.QueryThisYear();
                if (Nearly15MonthData.Count() == 0)
                {
                    linearAxisY.Maximum = 10;
                    linearAxisY.MajorStep = 2;
                    //linearAxisY.Minimum = -1;

                }
                else
                {
                    linearAxisY.Maximum = Nearly15MonthData.Count() * 1.2;
                    linearAxisY.MajorStep = Nearly15MonthData.Count() / 2;
                    // linearAxisY.Minimum = -(Nearly15MonthData.Count() / 8);

                }
                var date = start;
                var datad = new Collection<DateValue>();

                for (int i = 0; i <= 15; i++)
                {
                    double increment = 3600 * 24 * GetDay1(Convert.ToDateTime(Nearly15MonthData[i].Date));

                    var count = Nearly15MonthData.Where(d => (Convert.ToDateTime(d.Date).Month == Convert.ToDateTime(date).Month) && (Convert.ToDateTime(d.Date).Year == Convert.ToDateTime(date).Year)).Count();
                    //lineSeries1.Points.Add(new DataPoint(DateTimeAxis.ToDouble(Convert.ToDateTime(date.ToString("yyyy-MM"))), count));
                    datad.Add(new DateValue { Date = Convert.ToDateTime(date.ToString("yyyy-MM")), Value = count });
                    date = date.AddSeconds(increment);

                }
                lineSeries1.ItemsSource = datad;
                tmp.Series.Add(lineSeries1);


                //lineSeries1.ItemsSource = datad;
            }
            catch (Exception ex)
            {
                ShowErrorNotification(ex);
            }

OXYPlot 图表控件 显示X轴Log分布

上一篇:SQL SERVER 日期格式化、日期和字符串转换


下一篇:HDU 4034 Graph Floyd最短路