public static Image Generador_Grafico(System.Web.UI.WebControls.Image imagen, string nombreGrafico, TipoGraficos isEnum, string lgEjeX, string lgEjeY, params string[] strEntrada) { bool errorConfiguracion = false; bool ejes = false; int cantidadSeries = 0; //ChartSpaceClass objetoGraficoOffice = new ChartSpaceClass(); ChartSpace objetoGraficoOffice = new ChartSpace(); objetoGraficoOffice.DataSourceType = ChartDataSourceTypeEnum.chDataSourceTypeSpreadsheet; objetoGraficoOffice.HasChartSpaceTitle = true; objetoGraficoOffice.ChartSpaceTitle.Caption = nombreGrafico.ToUpper(); objetoGraficoOffice.ChartSpaceTitle.Font.set_Name("Tahoma"); objetoGraficoOffice.ChartSpaceTitle.Font.set_Size(12); objetoGraficoOffice.ChartSpaceTitle.Font.set_Bold(true); WCChart mapa = objetoGraficoOffice.Charts.Add(0); WCAxis Ejes; mapa.HasLegend = true; mapa.HasTitle = false; if (isEnum == TipoGraficos.PIE) { mapa.Type = ChartChartTypeEnum.chChartTypePie; mapa.SetData(ChartDimensionsEnum.chDimSeriesNames, (int)ChartSpecialDataSourcesEnum.chDataLiteral, "Elementos"); //revisamos cual es la serie y cuales son los datos //serie , A\tB\tC //datos , 1\t2\t3 for (int i = 0; i < strEntrada.Length; i++) { string[] separador = strEntrada[i].Split(','); if (separador[0].ToLower().Trim() == "serie") { mapa.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, separador[1]); } if (separador[0].ToLower().Trim() == "datos") { mapa.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, separador[1]); WCDataLabels dlValues = mapa.SeriesCollection[0].DataLabelsCollection.Add(); dlValues.HasPercentage = true; dlValues.HasValue = false; } } } if (isEnum == TipoGraficos.COLUMNAS || isEnum == TipoGraficos.LINEAS || isEnum == TipoGraficos.BARRAS || isEnum == TipoGraficos.AREA) { if (isEnum == TipoGraficos.COLUMNAS) { mapa.Type = ChartChartTypeEnum.chChartTypeColumnClustered; } if (isEnum == TipoGraficos.LINEAS) { mapa.Type = ChartChartTypeEnum.chChartTypeLineStacked; } if (isEnum == TipoGraficos.BARRAS) { mapa.Type = ChartChartTypeEnum.chChartTypeBarClustered; } if (isEnum == TipoGraficos.AREA) { mapa.Type = ChartChartTypeEnum.chChartTypeAreaStacked; } //serie,n,nombre serie //categoria,n,A\tB\tC //valores,n,1\t2\t3 ejes = true; for (int i = 0; i < strEntrada.Length; i++) { string[] separador = strEntrada[i].Split(','); if ((separador[0].ToLower().Trim() == "serie") && !errorConfiguracion) { //Buscamos las categorias y valores asociados a esta serie int indiceCategoria = BuscarIndice("categoria", separador[1].Trim(), strEntrada); int indiceValor = BuscarIndice("valores", separador[1].Trim(), strEntrada); if (indiceCategoria == -1 || indiceValor == -1) { errorConfiguracion = true; } else { string[] sepCategoria = strEntrada[indiceCategoria].Split(','); string[] sepValor = strEntrada[indiceValor].Split(','); mapa.SeriesCollection.Add(cantidadSeries); mapa.SeriesCollection[cantidadSeries].SetData(ChartDimensionsEnum.chDimSeriesNames, (int)ChartSpecialDataSourcesEnum.chDataLiteral, separador[2].Trim()); mapa.SeriesCollection[cantidadSeries].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, sepCategoria[2].Trim()); mapa.SeriesCollection[cantidadSeries].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, sepValor[2].Trim()); cantidadSeries += 1; } } } } if (isEnum == TipoGraficos.XY) { mapa.Type = ChartChartTypeEnum.chChartTypeScatterLine; //serie,n,nombreSerie //valores,n,X,1\t2\t3 //valores,n,Y,2\t4\t7 ejes = true; for (int i = 0; i < strEntrada.Length; i++) { string[] separador = strEntrada[i].Split(','); if ((separador[0].ToLower().Trim() == "serie") && !errorConfiguracion) { int indiceEjeX = BuscarIndice("valores", separador[1].Trim(), "X", strEntrada); int indiceEjeY = BuscarIndice("valores", separador[1].Trim(), "Y", strEntrada); if (indiceEjeY == -1 || indiceEjeX == -1) { errorConfiguracion = true; } else { string[] sepEjeX = strEntrada[indiceEjeX].Split(','); string[] sepEjeY = strEntrada[indiceEjeY].Split(','); mapa.SeriesCollection.Add(cantidadSeries); mapa.SeriesCollection[cantidadSeries].SetData(ChartDimensionsEnum.chDimSeriesNames, (int)ChartSpecialDataSourcesEnum.chDataLiteral, separador[2].Trim()); mapa.SeriesCollection[cantidadSeries].SetData(ChartDimensionsEnum.chDimXValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, sepEjeX[3].Trim()); mapa.SeriesCollection[cantidadSeries].SetData(ChartDimensionsEnum.chDimYValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, sepEjeY[3].Trim()); cantidadSeries += 1; } } } } if (ejes) { //Eje x Ejes = mapa.Axes[(int)ChartAxisPositionEnum.chAxisPositionBottom]; Ejes.HasTitle = true; Ejes.Title.Caption = lgEjeX; Ejes.Title.Font.set_Name("Tahoma"); Ejes.Title.Font.set_Size(8); Ejes.Title.Font.set_Bold(true); //Eje Y Ejes = mapa.Axes[(int)ChartAxisPositionEnum.chAxisPositionLeft]; Ejes.HasTitle = true; Ejes.Title.Caption = lgEjeY; Ejes.Title.Font.set_Name("Tahoma"); Ejes.Title.Font.set_Size(8); Ejes.Title.Font.set_Bold(true); } if (!errorConfiguracion) { try { objetoGraficoOffice.ExportPicture(strAbsolutePath, "gif", 500, 400); } catch (Exception e) { exceptions += "<br>error:" + e.ToString(); } imagen.ImageUrl = ConfigurationManager.AppSettings["PathToGraphics"] + "esttemp.gif"; } else { exceptions += "<br>error: Error de configuracion de series, categorias y valores"; } return(imagen); }
public string IdentificacaoCreateChart() { var jsonSerialiser = new JavaScriptSerializer(); List <DadosGraficos> list = new List <DadosGraficos>(); int totaisIdentificacao = 50; int TOTAIS_CONFORM = 150; int TOTAIS_NAOCONFORME = 13; int TOTAIS_OBSERVACAO = 35; list.Add(new DadosGraficos { label = "", displayValue = "35", value = "150", labelFontSize = "15", labelFontBold = "1", labelBorderPadding = "0 0 0 0", color = "#AFD249" }); list.Add(new DadosGraficos { label = "", displayValue = "13", value = "13", labelFontSize = "15", labelFontBold = "1", labelBorderPadding = "0 0 0 0", color = "#FDB813" }); list.Add(new DadosGraficos { label = "", displayValue = "35", value = "35", labelFontSize = "15", labelFontBold = "1", labelBorderPadding = "0 0 0 0", color = "#ED1C24" }); string data = jsonSerialiser.Serialize(list); ConfiguracaoChart Configuracao = new ConfiguracaoChart() { baseFontSize = "19", showBorder = "0", caption = "", labelDistance = "35", subCaption = "", numberPrefix = "", startingAngle = "90", decimals = "0", enableMultiSlicing = "0", use3DLighting = "0", defaultCenterLabel = "", pieRadius = "110", smartLineAlpha = "100", showLabels = "1", smartLineThickness = "1", showShadow = "0", captionFontSize = "14", subcaptionFontSize = "0", subcaptionFontBold = "0", centerLabelBold = "4", canvasBgColor = "#FFFFFF", canvasbordercolor = "#FFFFFF", baseFontColor = "#000000", bgColor = "#FFFFFF", doughnutRadius = "80", slicingDistance = "0", borderColor = "#FFFFFF", borderThickness = "0", borderAlpha = "0", theme = "", exportEnabled = "0", showPlotBorder = "0" }; string Config = jsonSerialiser.Serialize(Configuracao); string Chart = "{chart:" + Config + ",data:" + data + "}"; TipoGraficos Charts = new TipoGraficos() { chartType = "doughnut2d", chartId = "Identificacao", chartWidth = "300", chartHeight = "292", renderAt = null, bgColor = "#00000000", bgOpacity = null, dataFormat = "json", dataSource = null }; Chart dataIdentificacao = new Chart(Charts.chartType, Charts.chartId, Charts.chartWidth, Charts.chartHeight, Charts.dataFormat, Chart); var stringr = dataIdentificacao.Render().ToString(); return(dataIdentificacao.Render()); }