private void LoadFile_Click(object sender, RoutedEventArgs e) { dc.DataList.Clear(); ds = new DataSeries(); ds.DataString = tfr.LoadFile(); ds.LineColor = Brushes.DarkBlue; ds.FillColor = Brushes.DarkBlue; dc.DataList.Add(ds); AddChart(); }
public void AddChartStyle(TextBlock tbTitle, TextBlock tbXLabel, TextBlock tbYLabel, DataSeries ds) { Point pt = new Point(); Line tick = new Line(); double offset = 0; double dx, dy; TextBlock tb = new TextBlock(); // determin right offset: tb.Text = Ymax.ToString(); tb.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); Size size = tb.DesiredSize; rightOffset = size.Width / 2 + 2; // determine left offset: for (dy = Ymin; dy <= Ymax; dy += YTick) { pt = NormalizePoint(new Point(Xmin, dy)); tb = new TextBlock(); tb.Text = dy.ToString(); tb.TextAlignment = TextAlignment.Right; tb.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); size = tb.DesiredSize; if (offset < size.Width) offset = size.Width; } leftOffset = offset + 5; Canvas.SetLeft(ChartCanvas, leftOffset); Canvas.SetBottom(ChartCanvas, bottomOffset); ChartCanvas.Width = TextCanvas.Width - leftOffset - rightOffset; ChartCanvas.Height = TextCanvas.Height - bottomOffset - size.Height / 1.5; Rectangle chartRect = new Rectangle(); chartRect.Stroke = Brushes.Black; chartRect.Width = ChartCanvas.Width; chartRect.Height = ChartCanvas.Height; ChartCanvas.Children.Add(chartRect); // Create vertical gridlines: if(IsYGrid == true) { for (dx = Xmin + XTick; dx < Xmax; dx += XTick) { gridline = new Line(); AddLinePattern(); gridline.X1 = NormalizePoint(new Point(dx, Ymin)).X; gridline.Y1 = NormalizePoint(new Point(dx, Ymin)).Y; gridline.X2 = NormalizePoint(new Point(dx, Ymax)).X; gridline.Y2 = NormalizePoint(new Point(dx, Ymax)).Y; ChartCanvas.Children.Add(gridline); } } // Create horizontal gridlines: if (IsXGrid == true) { for (dy = Ymin + YTick; dy < Ymax; dy += YTick) { gridline = new Line(); AddLinePattern(); gridline.X1 = NormalizePoint(new Point(Xmin, dy)).X; gridline.Y1 = NormalizePoint(new Point(Xmin, dy)).Y; gridline.X2 = NormalizePoint(new Point(Xmax, dy)).X; gridline.Y2 = NormalizePoint(new Point(Xmax, dy)).Y; ChartCanvas.Children.Add(gridline); } } // Create x-axis tick marks: for (dx = Xmin; dx < Xmax; dx += xTick) { pt = NormalizePoint(new Point(dx, Ymin)); tick = new Line(); tick.Stroke = Brushes.Black; tick.X1 = pt.X; tick.Y1 = pt.Y; tick.X2 = pt.X; tick.Y2 = pt.Y - 5; ChartCanvas.Children.Add(tick); if (dx >= 0 && dx < ds.DataString.GetLength(1)) { tb = new TextBlock(); double d0 = DateToDouble(ds.DataString[0, 0]); double d1 = DateToDouble(ds.DataString[0, 1]); double d = DateToDouble(ds.DataString[0, (int)dx]); if (d0 > d1) d = DateToDouble(ds.DataString[0, ds.DataString.GetLength(1) - 1 - (int)dx]); tb.Text = DoubleToDate(d).ToString("m"); tb.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); size = tb.DesiredSize; TextCanvas.Children.Add(tb); Canvas.SetLeft(tb, leftOffset + pt.X - size.Width / 2); Canvas.SetTop(tb, pt.Y + 2 + size.Height / 2); } } // Create y-axis tick marks: for (dy = Ymin; dy <= Ymax; dy += YTick) { pt = NormalizePoint(new Point(Xmin, dy)); tick = new Line(); tick.Stroke = Brushes.Black; tick.X1 = pt.X; tick.Y1 = pt.Y; tick.X2 = pt.X + 5; tick.Y2 = pt.Y; ChartCanvas.Children.Add(tick); tb = new TextBlock(); tb.Text = dy.ToString(); tb.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); size = tb.DesiredSize; TextCanvas.Children.Add(tb); Canvas.SetRight(tb, ChartCanvas.Width + 10); Canvas.SetTop(tb, pt.Y); } // Add title and labels: tbTitle.Text = Title; tbXLabel.Text = XLabel; tbYLabel.Text = YLabel; tbXLabel.Margin = new Thickness(leftOffset + 2, 2, 2, 2); tbTitle.Margin = new Thickness(leftOffset + 2, 2, 2, 2); }
public void AddChartStyle(TextBlock tbTitle, TextBlock tbXLabel, TextBlock tbYLabel, DataSeries ds) { Point pt = new Point(); Line tick = new Line(); double offset = 0; double dx, dy; TextBlock tb = new TextBlock(); // determin right offset: tb.Text = Ymax.ToString(); tb.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); Size size = tb.DesiredSize; rightOffset = size.Width / 2 + 2; // determine left offset: for (dy = Ymin; dy <= Ymax; dy += YTick) { pt = NormalizePoint(new Point(Xmin, dy)); tb = new TextBlock(); tb.Text = dy.ToString(); tb.TextAlignment = TextAlignment.Right; tb.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); size = tb.DesiredSize; if (offset < size.Width) { offset = size.Width; } } leftOffset = offset + 5; Canvas.SetLeft(ChartCanvas, leftOffset); Canvas.SetBottom(ChartCanvas, bottomOffset); ChartCanvas.Width = TextCanvas.Width - leftOffset - rightOffset; ChartCanvas.Height = TextCanvas.Height - bottomOffset - size.Height / 1.5; Rectangle chartRect = new Rectangle(); chartRect.Stroke = Brushes.Black; chartRect.Width = ChartCanvas.Width; chartRect.Height = ChartCanvas.Height; ChartCanvas.Children.Add(chartRect); // Create vertical gridlines: if (IsYGrid == true) { for (dx = Xmin + XTick; dx < Xmax; dx += XTick) { gridline = new Line(); AddLinePattern(); gridline.X1 = NormalizePoint(new Point(dx, Ymin)).X; gridline.Y1 = NormalizePoint(new Point(dx, Ymin)).Y; gridline.X2 = NormalizePoint(new Point(dx, Ymax)).X; gridline.Y2 = NormalizePoint(new Point(dx, Ymax)).Y; ChartCanvas.Children.Add(gridline); } } // Create horizontal gridlines: if (IsXGrid == true) { for (dy = Ymin + YTick; dy < Ymax; dy += YTick) { gridline = new Line(); AddLinePattern(); gridline.X1 = NormalizePoint(new Point(Xmin, dy)).X; gridline.Y1 = NormalizePoint(new Point(Xmin, dy)).Y; gridline.X2 = NormalizePoint(new Point(Xmax, dy)).X; gridline.Y2 = NormalizePoint(new Point(Xmax, dy)).Y; ChartCanvas.Children.Add(gridline); } } // Create x-axis tick marks: for (dx = Xmin; dx < Xmax; dx += xTick) { pt = NormalizePoint(new Point(dx, Ymin)); tick = new Line(); tick.Stroke = Brushes.Black; tick.X1 = pt.X; tick.Y1 = pt.Y; tick.X2 = pt.X; tick.Y2 = pt.Y - 5; ChartCanvas.Children.Add(tick); if (dx >= 0 && dx < ds.DataString.GetLength(1)) { tb = new TextBlock(); double d0 = DateToDouble(ds.DataString[0, 0]); double d1 = DateToDouble(ds.DataString[0, 1]); double d = DateToDouble(ds.DataString[0, (int)dx]); if (d0 > d1) { d = DateToDouble(ds.DataString[0, ds.DataString.GetLength(1) - 1 - (int)dx]); } tb.Text = DoubleToDate(d).ToString("m"); tb.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); size = tb.DesiredSize; TextCanvas.Children.Add(tb); Canvas.SetLeft(tb, leftOffset + pt.X - size.Width / 2); Canvas.SetTop(tb, pt.Y + 2 + size.Height / 2); } } // Create y-axis tick marks: for (dy = Ymin; dy <= Ymax; dy += YTick) { pt = NormalizePoint(new Point(Xmin, dy)); tick = new Line(); tick.Stroke = Brushes.Black; tick.X1 = pt.X; tick.Y1 = pt.Y; tick.X2 = pt.X + 5; tick.Y2 = pt.Y; ChartCanvas.Children.Add(tick); tb = new TextBlock(); tb.Text = dy.ToString(); tb.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); size = tb.DesiredSize; TextCanvas.Children.Add(tb); Canvas.SetRight(tb, ChartCanvas.Width + 10); Canvas.SetTop(tb, pt.Y); } // Add title and labels: tbTitle.Text = Title; tbXLabel.Text = XLabel; tbYLabel.Text = YLabel; tbXLabel.Margin = new Thickness(leftOffset + 2, 2, 2, 2); tbTitle.Margin = new Thickness(leftOffset + 2, 2, 2, 2); }