private object CreateChartData2() { List <_Chart> chart2 = new List <_Chart>(); chart2.Clear(); var b = from p in list group p by p.name into g select new { g.Key, sum_cnt = g.Sum(p => p.cnt) }; foreach (var a in b) { _Chart chart = new _Chart(); string name = a.Key; Decimal Value = a.sum_cnt; chart.Name = name; chart.Value = Value; chart2.Add(chart); } sum2 = chart2.Sum(o => o.Value); return(chart2); }
private static void SetExcelChart(_Chart chartPage, string title) { chartPage.SetElement(MsoChartElementType.msoElementPrimaryCategoryAxisTitleAdjacentToAxis); chartPage.SetElement(MsoChartElementType.msoElementPrimaryValueAxisTitleAdjacentToAxis); chartPage.SetElement(MsoChartElementType.msoElementChartTitleAboveChart); chartPage.ChartTitle.Text = title; chartPage.Axes(XlAxisType.xlCategory).AxisTitle.Text = CategoryTitle; // chartPage.Axes(XlAxisType.xlValue).AxisTitle.Text = ValueTitle; chartPage.ChartType = XlChartType.xlLine; chartPage.Legend.Position = XlLegendPosition.xlLegendPositionBottom; chartPage.Axes(XlAxisType.xlCategory).CategoryType = XlCategoryType.xlTimeScale; chartPage.Axes(XlAxisType.xlCategory).MajorUnit = 100; chartPage.Axes(XlAxisType.xlCategory).MajorUnitScale = XlTimeUnit.xlDays; }
private List <_Chart> CreateChartData3(Biz.BizBusinessAnalysis.StatisticGlobalBean statisticGlobalBean) { List <_Chart> chart1 = new List <_Chart>(); chart1.Clear(); string name = ""; decimal vaule = 0; for (int i = 0; i < 6; i++) { _Chart chart = new _Chart(); switch (i) { case 0: name = "日均客流量"; vaule = Convert.ToDecimal(statisticGlobalBean.avgdaypeople); break; case 1: name = "人均价"; vaule = Convert.ToDecimal(statisticGlobalBean.avgsummoney); break; case 2: name = "菜品数量"; vaule = Convert.ToDecimal(statisticGlobalBean.itemNum); break; case 3: name = "会员占比"; vaule = Convert.ToDecimal(statisticGlobalBean.memuserpercent); break; case 4: name = "老顾客占比"; vaule = Convert.ToDecimal(statisticGlobalBean.olduserpercent); break; case 5: name = "进店周期"; vaule = Convert.ToDecimal(statisticGlobalBean.periodnum); break; } chart.Name = name; chart.Value = vaule; chart1.Add(chart); } return(chart1); }
private object CreateChartData() { List <_Chart> chart1 = new List <_Chart>(); chart1.Clear(); foreach (var a in list) { _Chart chart = new _Chart(); string name = a.itemname + "(" + a.name + ")"; Decimal Value = a.sum; chart.Name = name; chart.Value = Value; chart1.Add(chart); } sum1 = chart1.Sum(o => o.Value); return(chart1); }
/// <summary> /// Crée une courbe sur une nouvelle page graphique /// </summary> public void CreerGraphique(string NomFeuilleDonnees, string CellHautGauche, int NbreLignes, int NbreColonnes, string Titre, string CellSerie, string NomFeuille) { //Creation d'une nouvelle feuille graphique au début du classeur _MonGraphique = (_Chart)_MonClasseur.Sheets.Add(_MonClasseur.Sheets[1], _M, 1, XlWBATemplate.xlWBATChart); //type de graphique: Nuage de points avec ligne droites, sans marqueurs _MonGraphique.ChartType = XlChartType.xlXYScatterLinesNoMarkers; //Donne un nom à la feuille _MonGraphique.Name = NomFeuille; //Selection de la feuille ou sont les données pour ensuit creer le range _MaFeuille = (_Worksheet)_MonClasseur.Sheets[NomFeuilleDonnees]; //le range commence à CelleHautGauche, descend de NbreLignes, est large de NbreColonnes. Si CellSerie n'est pas dans le Range, alors ce sera le nom de la série _MonRange = _MaFeuille.get_Range(CellHautGauche, CellSerie).get_Resize(NbreLignes + 1, NbreColonnes); //Injecte la premiére série _MonGraphique.SetSourceData(_MonRange, XlRowCol.xlColumns); //Si la Série à un nom, c'est automaiquement le titre, on peut alors le modifier. if (_MonGraphique.HasTitle) { _MonGraphique.ChartTitle.Text = Titre; } //Récupére la série //Series _MaSerie = (Series)_MonGraphique.SeriesCollection(0); //lui donne un tire //_MaSerie.Name = NomSerie; //int toto = ((Lines)_MonGraphique.Lines(1)).Count; //Line maligne = (Line)_MonGraphique.Lines(0); //maligne.Duplicate(); }
public static int Main() { Console.WriteLine("Creating new Excel.Application"); Application app = new Application(); if (app == null) { Console.WriteLine("ERROR: EXCEL couldn't be started!"); return(0); } Console.WriteLine("Making application visible"); app.Visible = true; Console.WriteLine("Getting the workbooks collection"); Workbooks workbooks = app.Workbooks; Console.WriteLine("Adding a new workbook"); _Workbook workbook = workbooks.Add(XlWBATemplate.xlWBATWorksheet); Console.WriteLine("Getting the worksheets collection"); Sheets sheets = workbook.Worksheets; _Worksheet worksheet = (_Worksheet)sheets.get_Item(1); if (worksheet == null) { Console.WriteLine("ERROR: worksheet == null"); } Console.WriteLine("Setting the value for cell"); // This paragraph puts the value 5 to the cell G1 Range range1 = worksheet.get_Range("G1", Missing.Value); if (range1 == null) { Console.WriteLine("ERROR: range == null"); } const int nCells = 5; range1.Value2 = nCells; // This paragraph sends single dimension array to Excel Range range2 = worksheet.get_Range("A1", "E1"); int[] array2 = new int [nCells]; for (int i = 0; i < array2.GetLength(0); i++) { array2[i] = i + 1; } range2.Value2 = array2; // This paragraph sends two dimension array to Excel Range range3 = worksheet.get_Range("A2", "E3"); int[,] array3 = new int [2, nCells]; for (int i = 0; i < array3.GetLength(0); i++) { for (int j = 0; j < array3.GetLength(1); j++) { array3[i, j] = i * 10 + j; } } range3.Value2 = array3; // This paragraph reads two dimension array from Excel Range range4 = worksheet.get_Range("A2", "E3"); Object[,] array4; array4 = (Object[, ])range4.Value2; for (int i = array4.GetLowerBound(0); i <= array4.GetUpperBound(0); i++) { for (int j = array4.GetLowerBound(1); j <= array4.GetUpperBound(1); j++) { if ((double)array4[i, j] != array3[i - 1, j - 1]) { Console.WriteLine("ERROR: Comparison FAILED!"); return(0); } } } // This paragraph fills two dimension array with points for two curves and sends it to Excel Range range5 = worksheet.get_Range("A5", "J6"); double[,] array5 = new double[2, 10]; for (int j = 0; j < array5.GetLength(1); j++) { double arg = Math.PI / array5.GetLength(1) * j; array5[0, j] = Math.Sin(arg); array5[1, j] = Math.Cos(arg); } range5.Value2 = array5; // The following code draws the chart range5.Select(); ChartObjects chartobjects = (ChartObjects)worksheet.ChartObjects(Missing.Value); ChartObject chartobject = (ChartObject)chartobjects.Add(10 /*Left*/, 100 /*Top*/, 450 /*Width*/, 250 /*Height*/); _Chart chart = (_Chart)chartobject.Chart; // Call to chart.ChartWizard() is shown using late binding technique solely for the demonstration purposes Object[] args7 = new Object[11]; args7[0] = range5; // Source args7[1] = XlChartType.xl3DColumn; // Gallery args7[2] = Missing.Value; // Format args7[3] = XlRowCol.xlRows; // PlotBy args7[4] = 0; // CategoryLabels args7[5] = 0; // SeriesLabels args7[6] = true; // HasLegend args7[7] = "Sample Chart"; // Title args7[8] = "Sample Category Type"; // CategoryTitle args7[9] = "Sample Value Type"; // ValueTitle args7[10] = Missing.Value; // ExtraTitle chart.GetType().InvokeMember("ChartWizard", BindingFlags.InvokeMethod, null, chart, args7); Console.WriteLine("Press ENTER to finish the sample:"); Console.ReadLine(); try { // If user interacted with Excel it will not close when the app object is destroyed, so we close it explicitely workbook.Saved = true; app.UserControl = false; app.Quit(); } catch (COMException) { Console.WriteLine("User closed Excel manually, so we don't have to do that"); } Console.WriteLine("Sample successfully finished!"); return(100); }