예제 #1
0
        public void SetData(double value)
        {
            DateTime now = DateTime.Now;
            //long ticks = _stopwatch.ElapsedTicks;

            AnalyzeData data = new AnalyzeData();

            data.Now   = now;
            data.Value = value;
            data.Ticks = 0;

            _valuesLst.Add(data);

            chartControl1.Series["Torque"].Points.AddPoint(now, value);
            sync.Post(f =>
            {
                textEdit1.Text = "Atual Torque: " + Convert.ToString(value);
            }, value);
        }
예제 #2
0
        private string Save(string filePath, List <AnalyzeData> rpm, List <AnalyzeData> torque, List <AnalyzeData> traction)
        {
            //Set the output directory to the SampleApp folder where the app is running from.
            //Utils.OutputDir = new DirectoryInfo($"{AppDomain.CurrentDomain.BaseDirectory}SampleApp");

            string path     = Path.GetDirectoryName(filePath);
            string fileName = Path.GetFileName(filePath);

            Utils.OutputDir = new DirectoryInfo(path);
            FileInfo newFile = Utils.GetFileInfo(fileName, true);

            using (ExcelPackage package = new ExcelPackage(newFile))
            {
                ////////////////////////////////////////////////////////////////////
                /// RPM
                ////////////////////////////////////////////////////////////////////
                if (rpm != null && rpm.Count > 0)
                {
                    ExcelWorksheet worksheetRPM = package.Workbook.Worksheets.Add("RPM");

                    worksheetRPM.InsertRow(1, rpm.Count + 1);

                    worksheetRPM.Cells["A1"].Value = "Índices";
                    worksheetRPM.Cells["B1"].Value = "Horários";
                    worksheetRPM.Cells["C1"].Value = "Valor";

                    for (int i = 0; i < rpm.Count; i++)
                    {
                        int         idx  = i + 1 + 1;
                        AnalyzeData data = rpm[i];
                        if (data == null)
                        {
                            continue;
                        }

                        worksheetRPM.Cells[string.Format("A{0}", idx)].Value = idx - 1;
                        worksheetRPM.Cells[string.Format("B{0}", idx)].Value = data.Now.ToString();
                        worksheetRPM.Cells[string.Format("C{0}", idx)].Value = data.Value;
                    }

                    var chart = (worksheetRPM.Drawings.AddChart("LineMarkers", eChartType.LineMarkers) as ExcelLineChart);

                    chart.Title.Text = "Gráfico RPM";
                    //From row 1 colum 5 with five pixels offset
                    chart.SetPosition(0, 0, 5, 5);
                    chart.SetSize(800, 600);

                    ExcelAddress valueAddress = new ExcelAddress(2, 3, rpm.Count, 3);
                    var          ser          = (chart.Series.Add(valueAddress.Address, string.Format("B{0}:B{1}", 1, rpm.Count)) as ExcelLineChartSerie);
                    chart.DataLabel.ShowCategory = false;
                    chart.DataLabel.ShowPercent  = true;

                    chart.Legend.Border.LineStyle  = eLineStyle.Solid;
                    chart.Legend.Border.Fill.Style = eFillStyle.SolidFill;
                    //chart.Legend.Border.Fill.Color = Color.DarkBlue;

                    //Switch the PageLayoutView back to normal
                    worksheetRPM.View.PageLayoutView = false;
                }


                ////////////////////////////////////////////////////////////////////
                /// TORQUE
                ////////////////////////////////////////////////////////////////////

                if (torque != null && torque.Count > 0)
                {
                    ExcelWorksheet worksheetTorque = package.Workbook.Worksheets.Add("Torque");

                    worksheetTorque.InsertRow(1, torque.Count + 1);

                    worksheetTorque.Cells["A1"].Value = "Índices";
                    worksheetTorque.Cells["B1"].Value = "Horários";
                    worksheetTorque.Cells["C1"].Value = "Valor";

                    for (int i = 0; i < torque.Count; i++)
                    {
                        int         idx  = i + 1 + 1;
                        AnalyzeData data = torque[i];
                        if (data == null)
                        {
                            continue;
                        }

                        worksheetTorque.Cells[string.Format("A{0}", idx)].Value = idx - 1;
                        worksheetTorque.Cells[string.Format("B{0}", idx)].Value = data.Now.ToString();
                        worksheetTorque.Cells[string.Format("C{0}", idx)].Value = data.Value;
                    }

                    var chartTorque = (worksheetTorque.Drawings.AddChart("LineMarkers", eChartType.LineMarkers) as ExcelLineChart);

                    chartTorque.Title.Text = "Gráfico Tração";
                    //From row 1 colum 5 with five pixels offset
                    chartTorque.SetPosition(0, 0, 5, 5);
                    chartTorque.SetSize(800, 600);

                    ExcelAddress valueAddressTorque = new ExcelAddress(2, 3, torque.Count, 3);
                    var          serTorque          = (chartTorque.Series.Add(valueAddressTorque.Address, string.Format("B{0}:B{1}", 1, torque.Count)) as ExcelLineChartSerie);
                    chartTorque.DataLabel.ShowCategory = false;
                    chartTorque.DataLabel.ShowPercent  = true;

                    chartTorque.Legend.Border.LineStyle  = eLineStyle.Solid;
                    chartTorque.Legend.Border.Fill.Style = eFillStyle.SolidFill;
                    chartTorque.Legend.Border.Fill.Color = Color.DarkBlue;

                    //Switch the PageLayoutView back to normal
                    worksheetTorque.View.PageLayoutView = false;
                }


                ////////////////////////////////////////////////////////////////////
                /// Traction
                ////////////////////////////////////////////////////////////////////

                if (traction != null && traction.Count > 0)
                {
                    ExcelWorksheet worksheetTraction = package.Workbook.Worksheets.Add("Tração");

                    worksheetTraction.InsertRow(1, traction.Count + 1);

                    worksheetTraction.Cells["A1"].Value = "Índices";
                    worksheetTraction.Cells["B1"].Value = "Horários";
                    worksheetTraction.Cells["C1"].Value = "Valor";

                    for (int i = 0; i < traction.Count; i++)
                    {
                        int         idx  = i + 1;
                        AnalyzeData data = traction[i];
                        if (data == null)
                        {
                            continue;
                        }

                        worksheetTraction.Cells[string.Format("A{0}", idx)].Value = idx - 1;
                        worksheetTraction.Cells[string.Format("B{0}", idx)].Value = data.Now.ToString();
                        worksheetTraction.Cells[string.Format("C{0}", idx)].Value = data.Value;
                    }

                    var chartTraction = (worksheetTraction.Drawings.AddChart("LineMarkers", eChartType.LineMarkers) as ExcelLineChart);

                    chartTraction.Title.Text = "Gráfico Torque";

                    //From row 1 colum 5 with five pixels offset
                    chartTraction.SetPosition(0, 0, 5, 5);
                    chartTraction.SetSize(800, 600);

                    ExcelAddress valueAddressTraction = new ExcelAddress(2, 3, torque.Count, 3);
                    var          serTraction          = (chartTraction.Series.Add(valueAddressTraction.Address, string.Format("B{0}:B{1}", 1, traction.Count)) as ExcelLineChartSerie);
                    chartTraction.DataLabel.ShowCategory = false;
                    chartTraction.DataLabel.ShowPercent  = true;

                    chartTraction.Legend.Border.LineStyle  = eLineStyle.Solid;
                    chartTraction.Legend.Border.Fill.Style = eFillStyle.SolidFill;
                    chartTraction.Legend.Border.Fill.Color = Color.DarkBlue;

                    //Switch the PageLayoutView back to normal
                    worksheetTraction.View.PageLayoutView = false;
                }


                // save our new workbook and we are done!
                package.Save();
            }

            return(newFile.FullName);
        }