public static PlotModel HighLowSeries() { var model = new PlotModel { Title = "HighLowSeries", LegendSymbolLength = 24 }; var s1 = new HighLowSeries { Title = "HighLowSeries 1", Color = OxyColors.Black, }; var r = new Random(314); var price = 100.0; for (int x = 0; x < 24; x++) { price = price + r.NextDouble() + 0.1; var high = price + 10 + r.NextDouble() * 10; var low = price - (10 + r.NextDouble() * 10); var open = low + r.NextDouble() * (high - low); var close = low + r.NextDouble() * (high - low); s1.Items.Add(new HighLowItem(x, high, low, open, close)); } model.Series.Add(s1); model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, MaximumPadding = 0.3, MinimumPadding = 0.3 }); return(model); }
public static PlotModel HighLowSeries_DateTimeAxis() { var m = new PlotModel(); var x0 = DateTimeAxis.ToDouble(new DateTime(2013, 05, 04)); var a = new DateTimeAxis { Position = AxisPosition.Bottom, Minimum = x0 - 0.9, Maximum = x0 + 1.9, IntervalType = DateTimeIntervalType.Days, MajorStep = 1, MinorStep = 1, StringFormat = "yyyy-MM-dd" }; m.Axes.Add(a); var s = new HighLowSeries { TrackerFormatString = "X: {1:yyyy-MM-dd}\nHigh: {2:0.00}\nLow: {3:0.00}\nOpen: {4:0.00}\nClose: {5:0.00}" }; s.Items.Add(new HighLowItem(x0, 14, 10, 13, 12.4)); s.Items.Add(new HighLowItem(x0 + 1, 17, 8, 12.4, 16.3)); m.Series.Add(s); return(m); }
private void AdjustYExtent(HighLowSeries series, Axis xAxis, Axis yAxis) { //if (xAxis != null && yAxis != null && series.Items.Count != 0) //{ // var start = xAxis.ActualMinimum; // var end = xAxis.ActualMaximum; // var items = series.Items.FindAll(i => i.X >= start && i.X <= end); // var min = double.MaxValue; // var max = double.MinValue; // for (var i = 0; i <= items.Count - 1; i++) // { // min = Math.Min(min, items[i].Low); // max = Math.Max(max, items[i].High); // } // const double tolerance = 0.00000001; // //if (Math.Abs(min - double.MaxValue) > tolerance) // // yAxis.AbsoluteMinimum = min - min * YMinMaxOffsetPercent; // //if (Math.Abs(max - double.MinValue) > tolerance) // // yAxis.AbsoluteMaximum = max + max * YMinMaxOffsetPercent; // //xAxis. // //var extent = max - min; // //var margin = max * 2; //extent * 0.5; //change the 0 by a value to add some extra up and down margin // //yAxis.Zoom(min - margin, max + margin); //} }
public static PlotModel HighLowSeriesDateTimeAxis() { var m = new PlotModel(); var x0 = DateTimeAxis.ToDouble(new DateTime(2013, 05, 04)); var a = new DateTimeAxis { Position = AxisPosition.Bottom, Minimum = x0 - 0.9, Maximum = x0 + 1.9, IntervalType = DateTimeIntervalType.Days, MajorStep = 1, MinorStep = 1, StringFormat = "yyyy-MM-dd" }; m.Axes.Add(a); var s = new HighLowSeries { TrackerFormatString = "X: {1:yyyy-MM-dd}\nHigh: {2:0.00}\nLow: {3:0.00}\nOpen: {4:0.00}\nClose: {5:0.00}" }; s.Items.Add(new HighLowItem(x0, 14, 10, 13, 12.4)); s.Items.Add(new HighLowItem(x0 + 1, 17, 8, 12.4, 16.3)); m.Series.Add(s); return m; }
private void _setUpModel() { _plotModelPer = new PlotModel(); _plotModelPer.Axes.Add(new DateTimeAxis() { MajorGridlineStyle = LineStyle.Solid, MinorGridlineStyle = LineStyle.Dot, Position = AxisPosition.Bottom, StringFormat = "dd/MM" }); _plotModelPer.Axes.Add(new LinearAxis() { MajorGridlineStyle = LineStyle.Solid, MinorGridlineStyle = LineStyle.Dot, Position = AxisPosition.Left }); _plotModelTick = new PlotModel(); _plotModelTick.Axes.Add(new DateTimeAxis() { MajorGridlineStyle = LineStyle.Solid, MinorGridlineStyle = LineStyle.Dot, Position = AxisPosition.Bottom, StringFormat = "dd/MM" }); _plotModelTick.Axes.Add(new LinearAxis() { MajorGridlineStyle = LineStyle.Solid, MinorGridlineStyle = LineStyle.Dot, Position = AxisPosition.Left }); AddLineSeries(_plotModelPer, 0, "bal"); AddLineSeries(_plotModelPer, 1, "eq"); AddLineSeries(_plotModelTick, 0, "t"); var hls = new HighLowSeries { StrokeThickness = 1, Color = OxyColors.DarkGreen, TrackerFormatString = "X: {1:yy.MM.dd HHmm}\nOpen: {2:0.00}\nClose: {3:0.00}" }; _plotModelTick.Series.Add(hls); hls = new HighLowSeries { StrokeThickness = 1, Color = OxyColors.Red, TrackerFormatString = "X: {1:yy.MM.dd HHmm}\nOpen: {2:0.00}\nClose: {3:0.00}" }; _plotModelTick.Series.Add(hls); }
Task RenderHighLow(Series plot) { var highLowSeries = new HighLowSeries(); foreach (var item in plot.Data) { highLowSeries.Items.Add(new HighLowItem(item.X, item.High, item.Low, item.Open, item.Close)); } OxyplotModel.Series.Add(highLowSeries); return(Task.CompletedTask); }
public GanttChart() { InitializeComponent(); // 调换xy轴 _chart.View.Inverted = true; _chart.View.PlotBackground = new SolidColorBrush(Colors.White); // x轴为时间 _chart.View.AxisX.IsTime = true; // 设置y轴 Axis yAxis = _chart.View.AxisY; yAxis.Title = "分钟"; yAxis.MajorUnit = 20; yAxis.MinorGridStrokeThickness = 1; HighLowSeries ds = new HighLowSeries() { Label = "Left Room" }; ds.XValuesSource = new DateTime[] { new DateTime(2013, 10, 1), new DateTime(2013, 10, 1) }; ds.LowValuesSource = new double[] { 10, 30 }; ds.HighValuesSource = new double[] { 20, 50 }; ds.PointTooltipTemplate = Resources["label"] as DataTemplate; _chart.Data.Children.Add(ds); ds = new HighLowSeries() { Label = "Left Early" }; ds.XValuesSource = new DateTime[] { new DateTime(2013, 9, 15), new DateTime(2013, 10, 11), new DateTime(2013, 10, 16) }; ds.LowValuesSource = new double[] { 40, 53, 46 }; ds.HighValuesSource = new double[] { 60, 60, 60 }; ds.PointTooltipTemplate = Resources["label"] as DataTemplate; _chart.Data.Children.Add(ds); ds = new HighLowSeries() { Label = "Arrived Late" }; ds.XValuesSource = new DateTime[] { new DateTime(2013, 9, 5), new DateTime(2013, 10, 16) }; ds.LowValuesSource = new double[] { 0, 2 }; ds.HighValuesSource = new double[] { 10, 20 }; ds.PointTooltipTemplate = Resources["label"] as DataTemplate; ds.SymbolSize = new Size(30, 30); _chart.Data.Children.Add(ds); }
public void Reset() { LineSeries ls = _plotModelPer.Series[0] as LineSeries; ls.Points.Clear(); ls = _plotModelPer.Series[1] as LineSeries; ls.Points.Clear(); ls = _plotModelTick.Series[0] as LineSeries; ls.Points.Clear(); HighLowSeries hls = PlotModelTick.Series[1] as HighLowSeries; hls.Items.Clear(); hls = PlotModelTick.Series[2] as HighLowSeries; hls.Items.Clear(); }
public static PlotModel HighLowSeries() { var model = new PlotModel { Title = "HighLowSeries", LegendSymbolLength = 24 }; var s1 = new HighLowSeries { Title = "random values", Color = OxyColors.Black, }; var r = new Random(314); var price = 100.0; for (int x = 0; x < 24; x++) { price = price + r.NextDouble() + 0.1; var high = price + 10 + r.NextDouble() * 10; var low = price - (10 + r.NextDouble() * 10); var open = low + r.NextDouble() * (high - low); var close = low + r.NextDouble() * (high - low); s1.Items.Add(new HighLowItem(x, high, low, open, close)); } model.Series.Add(s1); model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, MaximumPadding = 0.3, MinimumPadding = 0.3 }); return model; }
//bool showXAxis = true, showYAxix = true, isZoomable = true, isMovable = true; //IPlotType chart; //public bool ShowXAxis //{ // get => showXAxis; // set // { // if (showXAxis == value) return; // showXAxis = value; // } //} //public bool ShowYAxix //{ // get => showYAxix; // set // { // if (showYAxix == value) return; // showYAxix = value; // } //} //public bool IsZoomable //{ // get => isZoomable; // set // { // if (isZoomable == value) return; // isZoomable = value; // } //} //public bool IsMovable //{ // get => isMovable; // set // { // if (isMovable == value) return; // isMovable = value; // } //} public async Task Add(PlotModel plotModel) { this.oxyplotModel = new OxyPlot.PlotModel(); this.oxyplotModel.Title = plotModel.Title; foreach (var chart in plotModel.Series) { if (chart is TwoColorArea) //it should be placed before Area if clause { var twoColorAreaSeries = new TwoColorAreaSeries { Color = ChartColor.CastToOxyColor(((TwoColorArea)chart).Color), Color2 = ChartColor.CastToOxyColor(((TwoColorArea)chart).Color2), Limit = ((TwoColorArea)chart).Limit }; foreach (var item in ((TwoColorArea)chart).Data) { twoColorAreaSeries.Points.Add(item); } this.oxyplotModel.Series.Add(twoColorAreaSeries); } else if (chart is Area) { var areaSeries = new AreaSeries(); foreach (var point in ((Area)chart).Data) { areaSeries.Points.Add(point); } this.oxyplotModel.Series.Add(areaSeries); } else if (chart is TwoColorLine)//it should be placed before line if clause { var twoColorLineSeries = new TwoColorLineSeries { Color = ChartColor.CastToOxyColor(((TwoColorLine)chart).Color), Color2 = ChartColor.CastToOxyColor(((TwoColorLine)chart).Color2), Limit = ((TwoColorLine)chart).Limit }; foreach (var item in ((TwoColorLine)chart).Data) { twoColorLineSeries.Points.Add(item); } this.oxyplotModel.Series.Add(twoColorLineSeries); } else if (chart is Line) { var lineSeries = new LineSeries { MarkerType = MarkerType.Circle, MarkerSize = 4, MarkerStroke = OxyColors.White }; foreach (var point in ((Line)chart).Data) { lineSeries.Points.Add(point); } this.oxyplotModel.Series.Add(lineSeries); } else if (chart is Pie) { var pieSeries = new PieSeries(); foreach (var slice in ((Pie)chart).Data) { pieSeries.Slices.Add(slice); } this.oxyplotModel.Series.Add(pieSeries); } else if (chart is Bar) { var barSeries = new BarSeries(); foreach (var item in ((Bar)chart).Data) { barSeries.Items.Add(item); } this.oxyplotModel.Series.Add(barSeries); } else if (chart is ErrorColumn) { var errorColumn = new ErrorColumnSeries(); foreach (ErrorColumnItem item in ((ErrorColumn)chart).Data) { errorColumn.Items.Add((OxyPlot.Series.ErrorColumnItem)item); } this.oxyplotModel.Series.Add(errorColumn); } else if (chart is Column) { var barSeries = new ColumnSeries(); foreach (var item in ((Column)chart).Data) { barSeries.Items.Add(item); } this.oxyplotModel.Series.Add(barSeries); } else if (chart is Box) { var boxSeries = new BoxPlotSeries(); foreach (var item in ((Box)chart).Data) { boxSeries.Items.Add(item); } this.oxyplotModel.Series.Add(boxSeries); } else if (chart is Contour) { var contourSeries = new ContourSeries { Data = ((Contour)chart).Data, ColumnCoordinates = ((Contour)chart).ColumnCoordinates, RowCoordinates = ((Contour)chart).RowCoordinates }; this.oxyplotModel.Series.Add(contourSeries); } else if (chart is RectangleBar) { var rectangleBarSeries = new RectangleBarSeries { Title = ((RectangleBar)chart).Title }; foreach (var item in ((RectangleBar)chart).Data) { rectangleBarSeries.Items.Add(item); } this.oxyplotModel.Series.Add(rectangleBarSeries); } else if (chart is CandleStick) { var candleStickSeries = new CandleStickSeries(); foreach (var item in ((CandleStick)chart).Data) { candleStickSeries.Items.Add(item); } this.oxyplotModel.Series.Add(candleStickSeries); } else if (chart is HeatMap) { var heatMapSeries = new HeatMapSeries() { Data = ((HeatMap)chart).Data, X0 = ((HeatMap)chart).X0, X1 = ((HeatMap)chart).X1, Y0 = ((HeatMap)chart).Y0, Y1 = ((HeatMap)chart).Y1, Interpolate = ((HeatMap)chart).Interpolate, RenderMethod = ((HeatMap)chart).RenderMethod }; this.oxyplotModel.Series.Add(heatMapSeries); } else if (chart is HighLow) { var highLowSeries = new HighLowSeries(); foreach (var item in ((HighLow)chart).Data) { highLowSeries.Items.Add(item); } this.oxyplotModel.Series.Add(highLowSeries); } else if (chart is IntervalBar) { var intervalBarSeries = new IntervalBarSeries(); foreach (var item in ((IntervalBar)chart).Data) { intervalBarSeries.Items.Add(item); } this.oxyplotModel.Series.Add(intervalBarSeries); } else if (chart is Scatter) { var scatterSeries = new ScatterSeries(); foreach (var item in ((Scatter)chart).Data) { scatterSeries.Points.Add(item); } this.oxyplotModel.Series.Add(scatterSeries); } } foreach (var axis in plotModel.Axes) { this.oxyplotModel.Axes.Add(axis); } }
private void SetTemperatureChart() { // read data CSVData data = new CSVData(); using (Stream stream = Assembly.GetExecutingAssembly(). GetManifestResourceStream("ChartSamples.Resources.weatherYear.csv")) { data.Read(stream, true, true); } int len = data.Length; WeatherData[] wdata = new WeatherData[len]; double min = double.MaxValue; double max = double.MinValue; // fill the array for (int i = 0; i < len; i++) { wdata[i] = new WeatherData(DateTime.Parse(data[i, 0]), double.Parse(data[i, "Max TemperatureF"]), double.Parse(data[i, "Mean TemperatureF"]), double.Parse(data[i, "Min TemperatureF"])); min = Math.Min(min, wdata[i].TMin); max = Math.Max(max, wdata[i].TMax); } if (len > 0) { chart.BeginUpdate(); chart.Data.Children.Clear(); chart.Data.ItemsSource = wdata; // create data series HighLowSeries ds = new HighLowSeries(); ds.ChartType = ChartType.Gantt; ds.Label = "Temp"; ds.LowValueBinding = new Binding("TMin"); ds.XValueBinding = new Binding("DateTime"); ds.HighValueBinding = new Binding("TMax"); ds.Style = this.Resources["highlowseries"] as Style; chart.Data.Children.Add(ds); XYDataSeries ds2 = new XYDataSeries(); ds2.ChartType = ChartType.Line; ds2.Label = "Average"; ds2.ValueBinding = new Binding("TAvg"); ds2.XValueBinding = new Binding("DateTime"); chart.Data.Children.Add(ds2); // set axis min and max chart.View.AxisX.Min = wdata[0].DateTime.Subtract(new TimeSpan(1, 0, 0, 0)).ToOADate(); chart.View.AxisX.Max = wdata[len - 1].DateTime.ToOADate(); chart.View.AxisY.Min = min; chart.View.AxisY.Max = max; // style chart chart.View.AxisX.IsTime = true; chart.View.AxisY.MajorTickThickness = 0; chart.View.AxisY.MinorTickThickness = 0; chart.View.AxisY.AxisLine = new Line() { StrokeThickness = 0 }; chart.View.AxisX.Scale = 0.4; chart.View.AxisX.ScrollBar = new AxisScrollBar(); chart.View.AxisX.MajorGridStrokeThickness = 0; chart.View.AxisX.MinorGridStrokeThickness = 0; chart.View.AxisX.MajorTickThickness = 0; chart.View.AxisX.MinorTickThickness = 0; chart.View.AxisX.AxisLine = new Line() { StrokeThickness = 0 }; chart.View.AxisY.Title = new TextBlock() { Text = "Temperature", HorizontalAlignment = System.Windows.HorizontalAlignment.Center }; chart.EndUpdate(); } }
private void SetTemperatureChart() { // read data CSVData data = new CSVData(); using (Stream stream = Assembly.GetExecutingAssembly(). GetManifestResourceStream("ChartSamples.Resources.weatherYear.csv")) { data.Read(stream, true, true); } int len = data.Length; WeatherData[] wdata = new WeatherData[len]; double min = double.MaxValue; double max = double.MinValue; // fill the array for (int i = 0; i < len; i++) { wdata[i] = new WeatherData(DateTime.Parse(data[i, 0]), double.Parse(data[i, "Max TemperatureF"]), double.Parse(data[i, "Mean TemperatureF"]), double.Parse(data[i, "Min TemperatureF"])); min = Math.Min(min, wdata[i].TMin); max = Math.Max(max, wdata[i].TMax); } if (len > 0) { chart.BeginUpdate(); chart.Data.Children.Clear(); chart.Data.ItemsSource = wdata; // create data series HighLowSeries ds = new HighLowSeries(); ds.ChartType = ChartType.Gantt; ds.Label = "Temp"; ds.LowValueBinding = new Binding("TMin"); ds.XValueBinding = new Binding("DateTime"); ds.HighValueBinding = new Binding("TMax"); ds.Style = this.Resources["highlowseries"] as Style; chart.Data.Children.Add(ds); XYDataSeries ds2 = new XYDataSeries(); ds2.ChartType = ChartType.Line; ds2.Label = "Average"; ds2.ValueBinding = new Binding("TAvg"); ds2.XValueBinding = new Binding("DateTime"); chart.Data.Children.Add(ds2); // set axis min and max chart.View.AxisX.Min = wdata[0].DateTime.Subtract(new TimeSpan(1, 0, 0, 0)).ToOADate(); chart.View.AxisX.Max = wdata[len - 1].DateTime.ToOADate(); chart.View.AxisY.Min = min; chart.View.AxisY.Max = max; // style chart chart.View.AxisX.IsTime = true; chart.View.AxisY.MajorTickThickness = 0; chart.View.AxisY.MinorTickThickness = 0; chart.View.AxisY.AxisLine = new Line() { StrokeThickness = 0 }; chart.View.AxisX.Scale = 0.4; chart.View.AxisX.ScrollBar = new AxisScrollBar(); chart.View.AxisX.MajorGridStrokeThickness = 0; chart.View.AxisX.MinorGridStrokeThickness = 0; chart.View.AxisX.MajorTickThickness = 0; chart.View.AxisX.MinorTickThickness = 0; chart.View.AxisX.AxisLine = new Line() { StrokeThickness = 0 }; chart.View.AxisY.Title = new TextBlock() { Text = "Temperature", HorizontalAlignment = System.Windows.HorizontalAlignment.Center }; chart.EndUpdate(); } }
private void _setUpModel() { _plotModelPer = new PlotModel(); _plotModelPer.Axes.Add(new DateTimeAxis() { MajorGridlineStyle = LineStyle.Solid, MinorGridlineStyle = LineStyle.Dot, Position = AxisPosition.Bottom, StringFormat = "dd/MM" }); _plotModelPer.Axes.Add(new LinearAxis() { MajorGridlineStyle = LineStyle.Solid, MinorGridlineStyle = LineStyle.Dot, Position = AxisPosition.Left }); _plotModelTick = new PlotModel(); _plotModelTick.Axes.Add(new DateTimeAxis() { MajorGridlineStyle = LineStyle.Solid, MinorGridlineStyle = LineStyle.Dot, Position = AxisPosition.Bottom, StringFormat = "dd/MM" }); _plotModelTick.Axes.Add(new LinearAxis() { MajorGridlineStyle = LineStyle.Solid, MinorGridlineStyle = LineStyle.Dot, Position = AxisPosition.Left }); AddLineSeries(_plotModelPer, 0, "bal"); AddLineSeries(_plotModelPer, 1, "eq"); AddLineSeries(_plotModelTick, 0, "t"); var hls = new HighLowSeries { StrokeThickness = 1, Color = OxyColors.DarkGreen, TrackerFormatString = "X: {1:yy.MM.dd HHmm}\nOpen: {2:0.00}\nClose: {3:0.00}" }; _plotModelTick.Series.Add(hls); hls = new HighLowSeries { StrokeThickness = 1, Color = OxyColors.Red, TrackerFormatString = "X: {1:yy.MM.dd HHmm}\nOpen: {2:0.00}\nClose: {3:0.00}" }; _plotModelTick.Series.Add(hls); }