public void SaveAsPNG() { string filename; try { if (ShowSaveFileDialog("png", "PNG files|*.png", out filename)) { //var pngExporter = new OxyPlot.Wpf.PngExporter { Width = (int)Plot.Width, Height = (int)Plot.Height, Background = OxyColors.White }; // OxyPlot.Wpf.PngExporter.Export(Plot, filename, (int)Plot.Width, (int)Plot.Height, OxyColors.White); using (var stream = File.Create(filename)) { var exporter = new OxyPlot.Wpf.PngExporter { Width = (int)Plot.Width, Height = (int)Plot.Height, Background = OxyColors.White }; exporter.Export(Plot, stream); } } } catch (Exception e) { System.Windows.MessageBox.Show(e.Message, "Error"); } }
public void SaveToFile(string filename) { using (var stream = File.Create(filename)) { var pngExporter = new OxyPlot.Wpf.PngExporter(); pngExporter.Export(this.PlotModel, stream); } }
/// <summary> /// Exports the plot to a .png file. /// </summary> public void ExportToPng(string path, int width = 800, int height = 600) { using (var s = File.Create(path)) { var pngExporter = new OxyPlot.Wpf.PngExporter { Width = width, Height = height, Background = OxyColors.White }; pngExporter.Export(Model, s); } }
/// <summary> /// Сохранение результирующего графика в формат PNG /// </summary> /// <param name="path">Путь к результирующему файлу</param> /// <param name="width">Ширина рисунка</param> /// <param name="height">Высота рисунка</param> public void SavePlotToPNG(string path, int width, int height) { using (FileStream s = new FileStream(path, FileMode.Create)) { var pngExporter = new OxyPlot.Wpf.PngExporter { Width = width, Height = height, Background = OxyColors.White }; pngExporter.Export(PlotModel, s); } }
public void ExportPlotBitmap(string path) { MemoryStream ms = new MemoryStream(); var pngExporter = new OxyPlot.Wpf.PngExporter { Width = 1024, Height = 768, Background = OxyColors.White }; pngExporter.Export(ThePlotModel, ms); var newImage = new Bitmap(ms); newImage.Save(path); }
private static void SavePlotToPng(string filePath, PlotModel plot) { // OxyPlot.WPF: requires STAThread, or new thread in STA using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)) { var pngExporter = new OxyPlot.Wpf.PngExporter() { Width = ExportImageWidth, Height = ExportImageHeight }; pngExporter.Export(plot, stream); } }
public static void SavePlotAsPNG(PlotModel plot, string filename, int horizontalRes, int verticalRes, bool isDarkMode) { var exporter = new OxyPlot.Wpf.PngExporter { Width = horizontalRes, Height = verticalRes, Background = isDarkMode ? OxyColor.Parse("#414b54") : OxyColor.Parse("#f2f2f2") }; using (var memoryStream = new MemoryStream()) { exporter.Export(plot, memoryStream); SaveFile(filename, "PNG files|*.png", "png", memoryStream.ToArray()); } }
// Exporting to Excel/Image Files /// <summary> /// Exports an OxyPlot PlotModel to a PNG image file /// </summary> /// <param name="plot"> The PlotModel to export </param> /// <param name="fileName"> The path to the image file to be created </param> public static void ExportImage(PlotModel plot, string fileName) { var export = new OxyPlot.Wpf.PngExporter(); export.Width = 1280; export.Height = 720; export.Background = OxyColors.White; MemoryStream stream = new MemoryStream(); FileStream file = new FileStream(fileName, FileMode.Create); export.Export(plot, stream); stream.WriteTo(file); file.Close(); stream.Close(); }
private void FuncToCall(object context) { //this is called when the button is clicked SaveFileDialog saveFileDialog = new SaveFileDialog(); if (saveFileDialog.ShowDialog() == true) { using (var stream = File.Create(saveFileDialog.FileName)) { var pngExporter = new OxyPlot.Wpf.PngExporter(); pngExporter.Height = 500; pngExporter.Width = 1500; pngExporter.Background = OxyColors.White; pngExporter.Resolution = 96; pngExporter.Export(plotModel, stream); } } }
public override void Execute() { if (_rawdata == null || _rawdata.Rows.Count == 0) { throw new ArgumentNullException("查無對應資料"); } _oxyrptLst = new List <IOxyRptOutput>(); #region Model = new PlotModel(); Model.Title = Title; #region x-axis setting //var xAxis = new DateTimeAxis //{ // StringFormat = "yyyy/MM/dd", // Title = XTitle, // MinorIntervalType = DateTimeIntervalType.Days, // IntervalType = DateTimeIntervalType.Days, // IsZoomEnabled = false, // TitleFontSize = 14, //}; //Model.Axes.Add(xAxis); CategoryAxis categoriesAxis = new CategoryAxis() { Position = AxisPosition.Bottom, IsZoomEnabled = false, }; ColumnSeries barChart = new ColumnSeries(); barChart.FillColor = OxyColor.FromRgb(121, 168, 225); // the rgb of minitab default #endregion #region y-axis setting LinearAxis yAxis = new LinearAxis() { IsZoomEnabled = false, Position = AxisPosition.Left, }; Model.Axes.Add(yAxis); #endregion #region add each data point to bar chart items foreach (DataRow row in _rawdata.Rows) { int emptyIndex = row[0].ToString().IndexOf(" "); categoriesAxis.ActualLabels.Add(row[0].ToString().Substring(0, emptyIndex)); barChart.Items.Add(new ColumnItem(Convert.ToDouble(row[1]))); } ; #endregion #region mouse click on bar barChart.MouseDown += (s, e) => { if (e.ChangedButton == OxyMouseButton.Left) { //if ((int)Math.Round(e.HitTestResult.Index) != indexOfNearestBarChart) IndexOfNearestBarChart = (int)Math.Round(e.HitTestResult.Index); e.Handled = true;// } else { } }; #endregion #region add warning line at y = 10 Model.Axes.Add(categoriesAxis); Model.Series.Add(barChart); var la = new LineAnnotation { Type = LineAnnotationType.Horizontal, Y = Warningline, Color = OxyColors.Red }; Model.Annotations.Add(la); #endregion #endregion #region fail method, sometimes successful, interesting var stream = new MemoryStream(); var pngExporter = new OxyPlot.Wpf.PngExporter { Width = 600, Height = 400, Background = OxyColors.White }; var thread = new Thread(() => { pngExporter.Export(this.Model, stream); }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); byte[] bytes = new byte[stream.Length]; stream.Seek(0, SeekOrigin.Begin); stream.Read(bytes, 0, bytes.Length); //can't write into bytes, length too long? bytes.Length stream.Close(); #endregion //將檔案轉為二進位陣列 this.OxyContents.Add(new OxyRptOutput() { OxyOType = OxyOType.GRAPH, OutputInByteArr = bytes, Tag = "Bar", }); this.OxyContents.Add(new OxyRptOutput() { OxyOType = OxyOType.TABLE, OutputInByteArr = Tool.ConvertDataSetToByteArray(statTable), }); }
public MemoryStream KayraKuva(Window win) { if (win.Name == "kiviohjelma") { Kiviohjelma _kivi = (Kiviohjelma)win; List <SeulakirjastoIndex> selist = new List <SeulakirjastoIndex>(); //Seulat joita on käytetty laskennassa, eli X-arvot. List <SeulaLapPros> tulist = new List <SeulaLapPros>(); //Läpäisyprosenttitulokset, eli Y-arvot List <Seulakirjasto> selistALL = new List <Seulakirjasto>(); //Kaikki seulat mitä on valittuna. Tehdään täysi X-akseli tällä. List <SeulaLapPros> sisOhjeAla = new List <SeulaLapPros>(); //Sisempi ohjealue, alempi ohje% List <SeulaLapPros> sisOhjeYla = new List <SeulaLapPros>(); //Sisempi ohjealue, ylempi ohje% List <SeulaLapPros> uloOhjeAla = new List <SeulaLapPros>(); //Ulompi ohjealue, alempi ohje% List <SeulaLapPros> uloOhjeYla = new List <SeulaLapPros>(); //Ulompi ohjealue, ylempi ohje% //Lukee tarvittavat prosenttiarvot ja lisää ne tulist-listaan //Ottaa valitut seulat ohjelmasta, ottaa talteen niiden sijainnin järjestyslukuna ja laittaa ne selist-listaan //Tuloksissa saattaa olla välejä (kaikkeja rivejä ei täytetty) joten koodi tarkistaa sen myös if (_kivi.lapaisypros1.Text != String.Empty) { SeulaLapPros sl = new SeulaLapPros { index = 0, tulos = Convert.ToDouble(_kivi.lapaisypros1.Text) }; tulist.Add(sl); string seulatxt = _kivi.Seula1.Text; seulatxt = seulatxt.Replace(".", ","); SeulakirjastoIndex ke = new SeulakirjastoIndex { index = 17, seula = Convert.ToDouble(seulatxt) }; selist.Add(ke); } if (_kivi.lapaisypros2.Text != String.Empty) { SeulaLapPros sl = new SeulaLapPros { index = 1, tulos = Convert.ToDouble(_kivi.lapaisypros2.Text) }; tulist.Add(sl); string seulatxt = _kivi.Seula2.Text; seulatxt = seulatxt.Replace(".", ","); SeulakirjastoIndex ke = new SeulakirjastoIndex { index = 16, seula = Convert.ToDouble(seulatxt) }; selist.Add(ke); } if (_kivi.lapaisypros3.Text != String.Empty) { SeulaLapPros sl = new SeulaLapPros { index = 2, tulos = Convert.ToDouble(_kivi.lapaisypros3.Text) }; tulist.Add(sl); string seulatxt = _kivi.Seula3.Text; seulatxt = seulatxt.Replace(".", ","); SeulakirjastoIndex ke = new SeulakirjastoIndex { index = 15, seula = Convert.ToDouble(seulatxt) }; selist.Add(ke); } if (_kivi.lapaisypros4.Text != String.Empty) { SeulaLapPros sl = new SeulaLapPros { index = 3, tulos = Convert.ToDouble(_kivi.lapaisypros4.Text) }; tulist.Add(sl); string seulatxt = _kivi.Seula4.Text; seulatxt = seulatxt.Replace(".", ","); SeulakirjastoIndex ke = new SeulakirjastoIndex { index = 14, seula = Convert.ToDouble(seulatxt) }; selist.Add(ke); } if (_kivi.lapaisypros5.Text != String.Empty) { SeulaLapPros sl = new SeulaLapPros { index = 4, tulos = Convert.ToDouble(_kivi.lapaisypros5.Text) }; tulist.Add(sl); string seulatxt = _kivi.Seula5.Text; seulatxt = seulatxt.Replace(".", ","); SeulakirjastoIndex ke = new SeulakirjastoIndex { index = 13, seula = Convert.ToDouble(seulatxt) }; selist.Add(ke); } if (_kivi.lapaisypros6.Text != String.Empty) { SeulaLapPros sl = new SeulaLapPros { index = 5, tulos = Convert.ToDouble(_kivi.lapaisypros6.Text) }; tulist.Add(sl); string seulatxt = _kivi.Seula6.Text; seulatxt = seulatxt.Replace(".", ","); SeulakirjastoIndex ke = new SeulakirjastoIndex { index = 12, seula = Convert.ToDouble(seulatxt) }; selist.Add(ke); } if (_kivi.lapaisypros7.Text != String.Empty) { SeulaLapPros sl = new SeulaLapPros { index = 6, tulos = Convert.ToDouble(_kivi.lapaisypros7.Text) }; tulist.Add(sl); string seulatxt = _kivi.Seula7.Text; seulatxt = seulatxt.Replace(".", ","); SeulakirjastoIndex ke = new SeulakirjastoIndex { index = 11, seula = Convert.ToDouble(seulatxt) }; selist.Add(ke); } if (_kivi.lapaisypros8.Text != String.Empty) { SeulaLapPros sl = new SeulaLapPros { index = 7, tulos = Convert.ToDouble(_kivi.lapaisypros8.Text) }; tulist.Add(sl); string seulatxt = _kivi.Seula8.Text; seulatxt = seulatxt.Replace(".", ","); SeulakirjastoIndex ke = new SeulakirjastoIndex { index = 10, seula = Convert.ToDouble(seulatxt) }; selist.Add(ke); } if (_kivi.lapaisypros9.Text != String.Empty) { SeulaLapPros sl = new SeulaLapPros { index = 8, tulos = Convert.ToDouble(_kivi.lapaisypros9.Text) }; tulist.Add(sl); string seulatxt = _kivi.Seula9.Text; seulatxt = seulatxt.Replace(".", ","); SeulakirjastoIndex ke = new SeulakirjastoIndex { index = 9, seula = Convert.ToDouble(seulatxt) }; selist.Add(ke); } if (_kivi.lapaisypros10.Text != String.Empty) { SeulaLapPros sl = new SeulaLapPros { index = 9, tulos = Convert.ToDouble(_kivi.lapaisypros10.Text) }; tulist.Add(sl); string seulatxt = _kivi.Seula10.Text; seulatxt = seulatxt.Replace(".", ","); SeulakirjastoIndex ke = new SeulakirjastoIndex { index = 8, seula = Convert.ToDouble(seulatxt) }; selist.Add(ke); } if (_kivi.lapaisypros11.Text != String.Empty) { SeulaLapPros sl = new SeulaLapPros { index = 10, tulos = Convert.ToDouble(_kivi.lapaisypros11.Text) }; tulist.Add(sl); string seulatxt = _kivi.Seula11.Text; seulatxt = seulatxt.Replace(".", ","); SeulakirjastoIndex ke = new SeulakirjastoIndex { index = 7, seula = Convert.ToDouble(seulatxt) }; selist.Add(ke); } if (_kivi.lapaisypros12.Text != String.Empty) { SeulaLapPros sl = new SeulaLapPros { index = 11, tulos = Convert.ToDouble(_kivi.lapaisypros12.Text) }; tulist.Add(sl); string seulatxt = _kivi.Seula12.Text; seulatxt = seulatxt.Replace(".", ","); SeulakirjastoIndex ke = new SeulakirjastoIndex { index = 6, seula = Convert.ToDouble(seulatxt) }; selist.Add(ke); } if (_kivi.lapaisypros13.Text != String.Empty) { SeulaLapPros sl = new SeulaLapPros { index = 12, tulos = Convert.ToDouble(_kivi.lapaisypros13.Text) }; tulist.Add(sl); string seulatxt = _kivi.Seula13.Text; seulatxt = seulatxt.Replace(".", ","); SeulakirjastoIndex ke = new SeulakirjastoIndex { index = 5, seula = Convert.ToDouble(seulatxt) }; selist.Add(ke); } if (_kivi.lapaisypros14.Text != String.Empty) { SeulaLapPros sl = new SeulaLapPros { index = 13, tulos = Convert.ToDouble(_kivi.lapaisypros14.Text) }; tulist.Add(sl); string seulatxt = _kivi.Seula14.Text; seulatxt = seulatxt.Replace(".", ","); SeulakirjastoIndex ke = new SeulakirjastoIndex { index = 4, seula = Convert.ToDouble(seulatxt) }; selist.Add(ke); } if (_kivi.lapaisypros15.Text != String.Empty) { SeulaLapPros sl = new SeulaLapPros { index = 14, tulos = Convert.ToDouble(_kivi.lapaisypros15.Text) }; tulist.Add(sl); string seulatxt = _kivi.Seula15.Text; seulatxt = seulatxt.Replace(".", ","); SeulakirjastoIndex ke = new SeulakirjastoIndex { index = 3, seula = Convert.ToDouble(seulatxt) }; selist.Add(ke); } if (_kivi.lapaisypros16.Text != String.Empty) { SeulaLapPros sl = new SeulaLapPros { index = 15, tulos = Convert.ToDouble(_kivi.lapaisypros16.Text) }; tulist.Add(sl); string seulatxt = _kivi.Seula16.Text; seulatxt = seulatxt.Replace(".", ","); SeulakirjastoIndex ke = new SeulakirjastoIndex { index = 2, seula = Convert.ToDouble(seulatxt) }; selist.Add(ke); } if (_kivi.lapaisypros17.Text != String.Empty) { SeulaLapPros sl = new SeulaLapPros { index = 16, tulos = Convert.ToDouble(_kivi.lapaisypros17.Text) }; tulist.Add(sl); string seulatxt = _kivi.Seula17.Text; seulatxt = seulatxt.Replace(".", ","); SeulakirjastoIndex ke = new SeulakirjastoIndex { index = 1, seula = Convert.ToDouble(seulatxt) }; selist.Add(ke); } if (_kivi.lapaisypros18.Text != String.Empty) { SeulaLapPros sl = new SeulaLapPros { index = 17, tulos = Convert.ToDouble(_kivi.lapaisypros18.Text) }; tulist.Add(sl); string seulatxt = _kivi.Seula18.Text; seulatxt = seulatxt.Replace(".", ","); SeulakirjastoIndex ke = new SeulakirjastoIndex { index = 0, seula = Convert.ToDouble(seulatxt) }; selist.Add(ke); } foreach (Control c in _kivi.seulaArvot.Children) //Kaikille esineille seulaArvot-canvasissa. Tarkoituksena ottaa kaikki valitut seulat dropdown-valikoista talteen { if (c.GetType() == typeof(ComboBox)) //jos esineen tyyppi on combobox { //Console.WriteLine("Combobox text: " + ((ComboBox)c).Text+", tag: "+ ((ComboBox)c).Tag); if (((ComboBox)c).Tag.ToString() != null) //Jos comboboxin tagi on tyhjä { if (((ComboBox)c).Tag.ToString() == "seula") //jos comboboxin tagi on "seula", eli kaikki seuladropdown-valikot { //Console.WriteLine(((ComboBox)c).Text); string seulatxt = ((ComboBox)c).Text; seulatxt = seulatxt.Replace(".", ","); Seulakirjasto ke = new Seulakirjasto { seula = Convert.ToDouble(seulatxt) }; selistALL.Add(ke); } } } } for (int i = 0; i < 4; i++)//Otetaan ohjealueet talteen yksi kolumni kerrallaan { switch (i) { case 0: int o = 17; foreach (Control c in _kivi.ohjeArvot.Children) { if (c.GetType() == typeof(TextBox)) { if (((TextBox)c).Tag.ToString() != null) { if (((TextBox)c).Tag.ToString() == "sisAla") { if (((TextBox)c).Text != String.Empty) { string seulatxt = ((TextBox)c).Text; seulatxt = seulatxt.Replace(".", ","); SeulaLapPros ohj = new SeulaLapPros { index = o, tulos = Convert.ToDouble(seulatxt) }; sisOhjeAla.Add(ohj); } o--; } } } } break; case 1: int k = 17; foreach (Control c in _kivi.ohjeArvot.Children) { if (c.GetType() == typeof(TextBox)) { if (((TextBox)c).Tag.ToString() != null) { if (((TextBox)c).Tag.ToString() == "sisYla") { if (((TextBox)c).Text != String.Empty) { string seulatxt = ((TextBox)c).Text; seulatxt = seulatxt.Replace(".", ","); SeulaLapPros ohj = new SeulaLapPros { index = k, tulos = Convert.ToDouble(seulatxt) }; sisOhjeYla.Add(ohj); } k--; } } } } break; case 2: int l = 17; foreach (Control c in _kivi.ohjeArvot.Children) { if (c.GetType() == typeof(TextBox)) { if (((TextBox)c).Tag.ToString() != null) { if (((TextBox)c).Tag.ToString() == "uloAla") { if (((TextBox)c).Text != String.Empty) { string seulatxt = ((TextBox)c).Text; seulatxt = seulatxt.Replace(".", ","); SeulaLapPros ohj = new SeulaLapPros { index = l, tulos = Convert.ToDouble(seulatxt) }; uloOhjeAla.Add(ohj); } l--; } } } } break; case 3: int m = 17; foreach (Control c in _kivi.ohjeArvot.Children) { if (c.GetType() == typeof(TextBox)) { if (((TextBox)c).Tag.ToString() != null) { if (((TextBox)c).Tag.ToString() == "uloYla") { if (((TextBox)c).Text != String.Empty) { string seulatxt = ((TextBox)c).Text; seulatxt = seulatxt.Replace(".", ","); SeulaLapPros ohj = new SeulaLapPros { index = m, tulos = Convert.ToDouble(seulatxt) }; uloOhjeYla.Add(ohj); } m--; } } } } break; default: break; } } //---------------------------------------------------------------------- //Luodaan listoista käyrä ja otetaan kuva //---------------------------------------------------------------------- PlotModel plotModel = new PlotModel(); plotModel.PlotType = PlotType.XY; plotModel.IsLegendVisible = false; plotModel.PlotMargins = new OxyThickness(15, 15, 15, 15); //asetetaan legendan asetukset //plotModel.LegendPosition = LegendPosition.TopRight; //plotModel.LegendOrientation = LegendOrientation.Horizontal; //plotModel.LegendPlacement = LegendPlacement.Outside; //Tehdään kokoelma, jossa on kaikki käytössä olevat seulat. Nämä sidotaan X-akseliin /*Collection<Item> items = new Collection<Item>(); * for (int i = selistALL.Count - 1; i >= 0; i--) * { * items.Add(new Item(selistALL[i].seula.ToString(), selistALL[i].seula)); * }*/ //Luodaan Y-akseli LinearAxis yaxis = new LinearAxis //Y-akseli { Maximum = 100, Minimum = 0, //Title = "Prosentti", TickStyle = TickStyle.Inside, MinorStep = 5, MinorGridlineStyle = LineStyle.Dot, Position = AxisPosition.Left, //AbsoluteMaximum = 100, //AbsoluteMinimum = 0, MajorStep = 10, //MinorStep = 5, MajorGridlineStyle = LineStyle.Dash, //MinorGridlineStyle = LineStyle.Dash, IsZoomEnabled = false, IsPanEnabled = false }; //------------------------------Logaritmiakseli------------------------- LogarithmicAxis xaxis = new LogarithmicAxis(); //X-akseli /* double yhteensa = 0; * foreach (Seulakirjasto value in selistALL) * { * yhteensa += value.seula; * }*/ //double keskimaara = yhteensa / kaikkiseulat.Count; //double logbase = 1.0 / Math.Log(Math.E, keskimaara); if (selist == null || tulist == null || selist.Count == 0 || tulist.Count == 0) { //xaxis.Title = "Seula"; xaxis.TickStyle = TickStyle.Inside; xaxis.Position = AxisPosition.Bottom; xaxis.MajorGridlineStyle = LineStyle.Solid; //xaxis.Base = logbase; //xaxis.MajorStep = 2; //xaxis.MinorGridlineStyle = LineStyle.Dash; //xaxis.Maximum = seulat[0].seula; //xaxis.Minimum = seulat[(seulat.Count - 1)].seula; xaxis.IsZoomEnabled = false; xaxis.IsPanEnabled = false; } else { //xaxis.Title = "Seula"; xaxis.TickStyle = TickStyle.Inside; xaxis.Position = AxisPosition.Bottom; xaxis.MajorGridlineStyle = LineStyle.Solid; //xaxis.Base = logbase; //xaxis.MajorStep = //xaxis.MinorGridlineStyle = LineStyle.Dash; xaxis.Maximum = selistALL[0].seula; xaxis.Minimum = selistALL[(selistALL.Count - 1)].seula; xaxis.IsZoomEnabled = false; xaxis.IsPanEnabled = false; } //------------------------------------------------------------------- //Luodaan X-akseli /*CategoryAxis caxis = new CategoryAxis();//X-akseli * * if (selist == null || tulist == null || selist.Count == 0 || tulist.Count == 0) //Jos jokin lista on tyhjä, luodaan tyhjä perusakseli * { * caxis.Title = "Seula"; * caxis.TickStyle = TickStyle.Inside; * caxis.Position = AxisPosition.Bottom; * caxis.IsTickCentered = true; * caxis.MajorGridlineStyle = LineStyle.Solid; * caxis.MajorGridlineColor = OxyColors.DarkSlateGray; * caxis.MajorTickSize = 7; * //caxis.Maximum = seulat[0].seula; * //caxis.Minimum = seulat[(seulat.Count - 1)].seula; * caxis.IsZoomEnabled = false; * caxis.IsPanEnabled = false; * caxis.MinorStep = 0.5; * caxis.MajorStep = 1; * caxis.ItemsSource = items; * caxis.LabelField = "Label"; * } * else * { * caxis.Title = "Seula"; * caxis.TickStyle = TickStyle.Inside; * caxis.Position = AxisPosition.Bottom; * caxis.IsTickCentered = true; * caxis.MajorGridlineStyle = LineStyle.Solid; * caxis.MajorGridlineColor = OxyColors.DarkSlateGray; * caxis.MajorTickSize = 7; * //caxis.Maximum = seulat[0].seula; * //caxis.Minimum = seulat[(seulat.Count-1)].seula; * caxis.IsZoomEnabled = false; * caxis.IsPanEnabled = false; * caxis.MinorStep = 0.5; * caxis.MajorStep = 1; * caxis.ItemsSource = items; * caxis.LabelField = "Label"; * } * for (int i = selistALL.Count - 1; i >= 0; i--) //Laittaa Y-akselille otsikot, eli seulat jotka on käytössä tällä hetkellä * { * caxis.ActualLabels.Add(selistALL[i].seula.ToString()); * }*/ LineSeries l1 = new LineSeries //Tuloskäyrä/viiva { Title = "Rakeisuuskäyrä", MarkerType = MarkerType.Circle, CanTrackerInterpolatePoints = false, MarkerSize = 3 //LabelFormatString = "Läp%: {1:0.0} %" }; //Luodaan itse viivat LineSeries ohje1 = new LineSeries { MarkerType = MarkerType.None, CanTrackerInterpolatePoints = false, MarkerSize = 1, Color = OxyColors.CadetBlue }; LineSeries ohje2 = new LineSeries { MarkerType = MarkerType.None, CanTrackerInterpolatePoints = false, MarkerSize = 0, Color = OxyColors.CadetBlue }; LineSeries ohje3 = new LineSeries { MarkerType = MarkerType.None, CanTrackerInterpolatePoints = false, MarkerSize = 0, Color = OxyColors.Indigo }; LineSeries ohje4 = new LineSeries { MarkerType = MarkerType.None, CanTrackerInterpolatePoints = false, MarkerSize = 0, Color = OxyColors.Indigo }; //selist.Reverse(); //Luodaan listat joihin tulee viivojen pisteet List <Pisteet> la = new List <Pisteet>(); //Pääviiva List <Pisteet> o1 = new List <Pisteet>(); List <Pisteet> o2 = new List <Pisteet>(); List <Pisteet> o3 = new List <Pisteet>(); List <Pisteet> o4 = new List <Pisteet>(); //------------------Käytetään CategoryAxisin kanssa-------------------- /*int j = 0; * for (int i = tulist.Count - 1; i >= 0; i--) * { * //Syötetään yhden pisteen koordinaatit listaan esineeksi * Pisteet l = new Pisteet(); * l.X = selist[i].index; * l.Y = tulist[j].tulos; * la.Add(l); * j++; * }//--------------------------------------------------------------------*/ //---------------Käytetään LogarithmAxisin kanssa--------------------- for (int i = 0; i < tulist.Count; i++) { Pisteet l = new Pisteet(); l.X = selist[i].seula;//seulat[i].seula kun käytetään LogarithmAxisia l.Y = tulist[i].tulos; la.Add(l); }//--------------------------------------------------------------------*/ for (int i = sisOhjeAla.Count - 1; i >= 0; i--) { Pisteet l = new Pisteet(); l.X = sisOhjeAla[i].index; l.Y = sisOhjeAla[i].tulos; o1.Add(l); } for (int i = sisOhjeYla.Count - 1; i >= 0; i--) { Pisteet l = new Pisteet(); l.X = sisOhjeYla[i].index; l.Y = sisOhjeYla[i].tulos; o2.Add(l); } for (int i = uloOhjeAla.Count - 1; i >= 0; i--) { Pisteet l = new Pisteet(); l.X = uloOhjeAla[i].index; l.Y = uloOhjeAla[i].tulos; o3.Add(l); } for (int i = uloOhjeYla.Count - 1; i >= 0; i--) { Pisteet l = new Pisteet(); l.X = uloOhjeYla[i].index; l.Y = uloOhjeYla[i].tulos; o4.Add(l); } //Laitetaan luodut pistelistat viivoihinsa foreach (Pisteet e in la) { l1.Points.Add(new DataPoint(e.X, e.Y)); } foreach (Pisteet e in o1) { ohje1.Points.Add(new DataPoint(e.X, e.Y)); } foreach (Pisteet e in o2) { ohje2.Points.Add(new DataPoint(e.X, e.Y)); } foreach (Pisteet e in o3) { ohje3.Points.Add(new DataPoint(e.X, e.Y)); } foreach (Pisteet e in o4) { ohje4.Points.Add(new DataPoint(e.X, e.Y)); } //----------------------Kovakoodatut arvot, testitapaus----------------------------- /*double[] ar = new double[] { 0.063, 0.125, 0.25, 0.5, 1, 2, 4, 6, 8, 12, 16, 18, 20, 25, 30, 64, 100, 200 }; * double[] er = new double[] { 1.8, 3, 4.5, 5.6, 6.5, 8.3, 9.0, 9.9, 13.8, 15.6, 16.5, 17.4, 18.6, 20.4, 30.8, 31.4, 50.5, 62.7 }; * List<Pisteet> la = new List<Pisteet>(); * for (int i = 0; i < ar.Length; i++)//prosentit.Count * { * Pisteet l = new Pisteet(); * l.X = ar[i]; * l.Y = er[i]; * la.Add(l); * } * foreach (Pisteet e in la) * { * l1.Points.Add(new DataPoint(e.X, e.Y)); * }*///----------------------------------------------------------------------------------- //Syötetään kaikki luodut viivat ja akselit kaavioon plotModel.Axes.Add(yaxis); plotModel.Axes.Add(xaxis); //plotModel.Axes.Add(caxis); plotModel.Series.Add(l1); plotModel.Series.Add(ohje1); plotModel.Series.Add(ohje2); plotModel.Series.Add(ohje3); plotModel.Series.Add(ohje4); //Palautetaan kuva viivakaaviosta var kuvastream = new MemoryStream(); var pngExporter = new OxyPlot.Wpf.PngExporter { Width = 750, Height = 500, Background = OxyColors.White }; pngExporter.Export(plotModel, kuvastream); return(kuvastream); } else { return(null); } }
public override void Execute() { if (_rawdata == null || _rawdata.Rows.Count == 0) { throw new ArgumentNullException("查無對應資料"); } _oxyrptLst = new List <IOxyRptOutput>(); #region create oxy code // This data would be used in bar chart too, so move it to view model. // Here we only handle the PlotModel //// Initialize in View Model //_rptLst = new List<IOxyRptOutput>(); //重新建立一個分析結果列舉 //DataTable distinctPlant = new DataTable(); //// search different plant //distinctPlant.Columns.Add("Plant", typeof(int)); //foreach(DataRow row in RawData.Rows) //{ // if (!(distinctPlant.Rows.Find(row[0])==row[0])) // { // DataRow addrow = new DataRow(); // addrow[0] = row[0]; // distinctPlant.Rows.Add(addrow); // } //}; //DataTable ComputeResult = new DataTable(); //ComputeResult.Columns.Add("Plant", typeof(int)); //ComputeResult.Columns.Add("Max MR", typeof(int)); //foreach (DataRow row in distinctPlant.Rows) //{ // DataRow dt = new DataRow(); // dt[0] = row; // DataTable tmpdt= new DataTable(); // tmpdt.Rows.Add(RawData.Rows.Find(row)); //}; //RawData.Columns.Add("Plant", typeof(int)); //RawData.Columns.Add("Max MR", typeof(int)); Model = new PlotModel(); Model.IsLegendVisible = true; Model.Title = Title; PieSeries pieSeries = new PieSeries(); //RawData.DefaultView.Sort = "Plant DESC"; //int countRangeOver10 = 0; //int countRangeUnover10 = 0; int tmpIndex = 0; foreach (DataRow row in _rawdata.Rows) { tmpIndex++; if (tmpIndex == 1) { pieSeries.Slices.Add(new PieSlice((string)row[0], Convert.ToDouble(row[1])) { IsExploded = false, Fill = OxyColors.PaleVioletRed }); } else { pieSeries.Slices.Add(new PieSlice((string)row[0], Convert.ToDouble(row[1])) { IsExploded = true }); } } ; Model.Series.Add(pieSeries); //查無資料 construct #endregion #region Thread to solve //var stream = new MemoryStream(); var stream = new MemoryStream(); var pngExporter = new OxyPlot.Wpf.PngExporter { Width = 600, Height = 400, Background = OxyColors.White }; var thread = new Thread(() => { pngExporter.Export(this.Model, stream); }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); byte[] bytes = new byte[stream.Length]; stream.Seek(0, SeekOrigin.Begin); stream.Read(bytes, 0, bytes.Length); //can't write into bytes, length too long? bytes.Length stream.Close(); //stream.Seek(0, SeekOrigin.Begin); #endregion // untry method , but it seems not for this problem //using (MemoryStream ms = new MemoryStream()) //{ // using (DeflateStream ds = new DeflateStream(ms, CompressionMode.Compress)) // { // ds.Write(data, 0, data.Length); // ds.Flush(); // } // return ms.ToArray(); //} Console.WriteLine(""); //pngExporter. //將檔案轉為二進位陣列 this.OxyContents.Add(new OxyRptOutput() { OxyOType = OxyOType.GRAPH, OutputInByteArr = bytes, Tag = "Pie", }); }
private void Button_Click(object sender, RoutedEventArgs e) { OxyPlot.Wpf.PngExporter pe = new OxyPlot.Wpf.PngExporter(); var f = File.Create(@"D:\t1.png"); pe.Export(plotView1.Model, f); }
public override void Execute() { if (_rawdata == null || _rawdata.Rows.Count == 0) { System.Windows.MessageBox.Show("部分爐區資料數不足,請重新確認時間範圍"); //throw new ArgumentNullException("查無對應資料"); } _oxyrptLst = new List <IOxyRptOutput>(); Model = new PlotModel(); Model.Title = base.Title; #region basic setting for LineSeries LineSeries lineSeries = new LineSeries() { //LabelFormatString = "{0:.00}", MarkerType = OxyPlot.MarkerType.Circle, MarkerSize = 4, MarkerFill = OxyColor.FromRgb(121, 168, 225), //TrackerFormatString = "{0} " + Environment.NewLine + "{1}: {2} " + Environment.NewLine + "{3}: {4:0.00} ", TrackerFormatString = "{4:0.00}", CanTrackerInterpolatePoints = false, //LabelFormatString = "{4:0.00 }", }; lineSeries.Color = OxyColor.FromRgb(121, 168, 225); foreach (DataRow row in RawData.Rows) { lineSeries.Points.Add(new DataPoint(DateTimeAxis.ToDouble(row[0]), Math.Round(System.Convert.ToDouble(row[1]), 2))); } Model.Series.Add(lineSeries); #endregion #region setting for Axes var xAxis = new DateTimeAxis { StringFormat = "yyyy/MM/dd", Title = XTitle, MinorIntervalType = DateTimeIntervalType.Days, IntervalType = DateTimeIntervalType.Days, IsZoomEnabled = false, TitleFontSize = 14, }; //test LinearAxis to y-axis for fixed max and min //Model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = 200, Maximum = 600, IsAxisVisible = true }); // test LinearAxis to y-axis for appearance interval var yAxis = new LinearAxis { Position = AxisPosition.Left, Title = YTitle, IntervalLength = 10, IsZoomEnabled = false, TitleFontSize = 14, Maximum = Max * 1.1, Minimum = Min * 0.9, //LabelFormatter = ValueAxisLabelFormatter, //StringFormat = "0.00", //LabelFormatString = "{0:.00}", }; Model.Axes.Add(yAxis); Model.Axes.Add(xAxis); #endregion #region add warning line var la = new LineAnnotation { Type = LineAnnotationType.Horizontal, Y = warningline, Color = OxyColors.Red }; Model.Annotations.Add(la); #endregion #region fail method, sometimes successful, interesting //var stream = new MemoryStream(); var stream = new MemoryStream(); var pngExporter = new OxyPlot.Wpf.PngExporter { Width = 600, Height = 400, Background = OxyColors.White }; var thread = new Thread(() => { pngExporter.Export(this.Model, stream); }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); byte[] bytes = new byte[stream.Length]; stream.Seek(0, SeekOrigin.Begin); stream.Read(bytes, 0, bytes.Length); //can't write into bytes, length too long? bytes.Length stream.Close(); #endregion #region mouse click close lineSeries.MouseDown += (s, e) => { if (e.ChangedButton == OxyMouseButton.Left) { e.Handled = true;// } else { } }; #endregion //pngExporter. //將檔案轉為二進位陣列 this.OxyContents.Add(new OxyRptOutput() { OxyOType = OxyOType.GRAPH, OutputInByteArr = bytes, Tag = this.Tag, }); #region if MR, compute stat table if (Tag == "MR") { this.OxyContents.Add(new OxyRptOutput() { OxyOType = OxyOType.TABLE, OutputInByteArr = Tool.ConvertDataSetToByteArray(statTable), }); } #endregion }
public override void Execute() { if (_rawdata == null || _rawdata.Rows.Count == 0) { throw new ArgumentNullException("查無對應資料"); } _oxyrptLst = new List <IOxyRptOutput>(); #region Model = new PlotModel(); Model.Title = Title; #region x-axis setting CategoryAxis categoriesAxis = new CategoryAxis() { Position = AxisPosition.Bottom, IsZoomEnabled = false, }; ColumnSeries barChart = new ColumnSeries(); barChart.FillColor = OxyColor.FromRgb(121, 168, 225); // the rgb of minitab default if (_rawdata.Rows.Count > 10) { categoriesAxis.Angle = 90; } #endregion #region y-axis setting LinearAxis yAxis = new LinearAxis() { IsZoomEnabled = false, Position = AxisPosition.Left, }; Model.Axes.Add(yAxis); #endregion //barChart.Title = BarTitle; #region add each data point to bar chart items int iCnt = 0; // only 50 appears in the graph foreach (DataRow row in _rawdata.Rows) { if (iCnt > 49) { break; } categoriesAxis.ActualLabels.Add(row[0].ToString()); barChart.Items.Add(new ColumnItem(Convert.ToDouble(row[1]))); iCnt++; } ; #endregion #region mouse click on bar barChart.MouseDown += (s, e) => { if (e.ChangedButton == OxyMouseButton.Left) { if ((int)Math.Round(e.HitTestResult.Index) != indexOfNearestBarChart) { IndexOfNearestBarChart = (int)Math.Round(e.HitTestResult.Index); } //int indexOfNearestBarChart = (int)Math.Round(e.HitTestResult.Index); // var nearestBarChart = series.Transform(series.Items[indexOfNearestBarChart]); //bool tmpa = series.IsItemSelected(indexOfNearestBarChart); //barChart.Items.ElementAt(indexOfNearestBarChart); //move //int a = 0; //move e.Handled = true;// } else { } }; #endregion #region add warning line at y = 10 Model.Axes.Add(categoriesAxis); Model.Series.Add(barChart); var la = new LineAnnotation { Type = LineAnnotationType.Horizontal, Y = Warningline, Color = OxyColors.Red }; Model.Annotations.Add(la); #endregion #endregion #region fail method, sometimes successful, interesting //var stream = new MemoryStream(); var stream = new MemoryStream(); var pngExporter = new OxyPlot.Wpf.PngExporter { Width = 600, Height = 400, Background = OxyColors.White }; var thread = new Thread(() => { pngExporter.Export(this.Model, stream); }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); byte[] bytes = new byte[stream.Length]; stream.Seek(0, SeekOrigin.Begin); stream.Read(bytes, 0, bytes.Length); //can't write into bytes, length too long? bytes.Length stream.Close(); //stream.Seek(0, SeekOrigin.Begin); #endregion //pngExporter. //將檔案轉為二進位陣列 this.OxyContents.Add(new OxyRptOutput() { OxyOType = OxyOType.GRAPH, OutputInByteArr = bytes, Tag = "Bar", }); }