Ejemplo n.º 1
0
        public void Create3DChart(string chartName, string chartTitle, ExcelWorksheetWrapper to,
                                  string[] axisTitles, int height = 20)
        {
            var chart = to.Worksheet.Drawings.AddChart(chartName, eChartType.Surface);

            chart.Title.Text = chartTitle;
            for (var i = _pos1Line; i <= _pos2Line; i++)
            {
                var signaturesAddress = string.Format("{0}{1}:{0}{2}", (char)(_pos1Column + 64),
                                                      _pos1Line, _pos2Line);
                var dataAddress = string.Format("{0}{1}:{2}{1}", (char)(_pos1Column + 64 + 1),
                                                i, (char)(_pos2Column + 64));
                var serie = chart.Series.Add(ExcelRange.GetFullAddress(Worksheet.Name, dataAddress),
                                             ExcelRange.GetFullAddress(Worksheet.Name, signaturesAddress));
                serie.Header = Worksheet.Cells[string.Format("{0}{1}", (char)(_pos1Column + 64), i)].Value.ToString();
            }
            chart.Legend.Position    = eLegendPosition.Right;
            chart.XAxis.Title.Text   = axisTitles[0];
            chart.YAxis.Title.Text   = "SigmaMin";
            chart.Axis[2].Title.Text = "B";

            for (var i = 0; i < chart.Axis.Length; i++)
            {
                chart.Axis[i].Title.Text      = axisTitles[i];
                chart.Axis[i].Title.Font.Size = 12;
            }

            to.PlaceChart(chart, 20);
        }
Ejemplo n.º 2
0
        public void CreateChart(string chartName, string chartTitle, ExcelWorksheetWrapper to, int height = 10)
        {
            var chart = to.Worksheet.Drawings.AddChart(chartName, eChartType.ColumnClustered);

            chart.Title.Text = chartTitle;
            var address1 = string.Format("{0}{1}:{2}{3}",
                                         (char)(_pos2Column + 64), _pos1Line, (char)(_pos2Column + 64), _pos2Line);
            var address2 = string.Format("{0}{1}:{2}{3}",
                                         (char)(_pos1Column + 64), _pos1Line, (char)(_pos1Column + 64), _pos2Line);

            chart.Series.Add(ExcelRange.GetFullAddress(Worksheet.Name, address1),
                             ExcelRange.GetFullAddress(Worksheet.Name, address2));
            chart.Legend.Remove();

            to.PlaceChart(chart, height);
        }
Ejemplo n.º 3
0
        public void addSeries(string chartName, double[,] data, string dataName, string infoChart = "", string infoData = "")
        {
            // Finding the chart
            ExcelDrawing objChart = null;
            int          nCharts  = charts_.Count;

            for (int i = 0; i != nCharts; ++i)
            {
                ExcelDrawing chart = charts_[i];
                if (chart.Name == chartName)
                {
                    objChart   = chart;
                    lastSheet_ = chartSheets_[i];
                    break;
                }
            }
            if (objChart == null)
            {
                return;
            }
            // Check if the chart is currently in use
            ChartPosition pos;
            int           iRow, jCol;

            if (!posCharts_.ContainsKey(objChart))
            {
                pos = new ChartPosition()
                {
                    header = new Position {
                        row = ChartPosition.lastRow + 1, col = 1
                    },
                    length            = data.GetLength(0),
                    availablePosition = new Position {
                        row = ChartPosition.lastRow + 3, col = 1
                    }
                };
                // Write the header
                workSheet_.Cells[pos.header.row, pos.header.col].Value = objChart.Name + infoChart;
                posCharts_.Add(objChart, pos);
                ChartPosition.lastRow += pos.length + 3;
            }
            else
            {
                pos = posCharts_[objChart];
            }
            // Add the function values
            iRow = pos.availablePosition.row;
            jCol = pos.availablePosition.col;
            int nData = data.GetLength(0);

            for (int k = 0; k != nData; ++k)
            {
                workSheet_.Cells[iRow + k, jCol].Value     = data[k, 0];
                workSheet_.Cells[iRow + k, jCol + 1].Value = data[k, 1];
            }
            workSheet_.Cells[pos.header.row + 1, jCol].Value     = infoData; // Set the data info
            workSheet_.Cells[pos.header.row + 1, jCol + 1].Value = dataName; // Set the name
            // Retrieving the data address
            ExcelScatterChart scatterChart = (ExcelScatterChart)objChart;
            string            xVals        = ExcelRange.GetAddress(iRow, jCol,
                                                                   iRow + nData - 1, jCol);
            string yVals = ExcelRange.GetAddress(iRow, jCol + 1,
                                                 iRow + nData - 1, jCol + 1);

            xVals = ExcelRange.GetFullAddress(workSheetName_, xVals);
            yVals = ExcelRange.GetFullAddress(workSheetName_, yVals);
            // Creating the serie
            ExcelScatterChartSerie serie = scatterChart.Series.Add(yVals, xVals);
            // Using the standard markers when custom ones are not available
            List <MarkerProperty> markers = customMarkers_[chartName];

            if (markers == null || markers.Count == 0)
            {
                markers = standardMarkers_;
            }
            MarkerProperty markerProperties = markers[indMarkers_[chartName]];
            // Using the standard lines when custom ones are not available
            List <LineProperty> lines = customLines_[chartName];

            if (lines == null || lines.Count == 0)
            {
                lines = standardLines_;
            }
            LineProperty lineProperties = lines[indLines_[chartName]];
            int          transparency   = lineProperties.isTransparent ? 100 : 0; // Perecentage

            // Specifying the properties
            serie.Border.Fill.Color        = Color.Black;              // Line color
            serie.Border.LineStyle         = lineProperties.lineStyle; // Line style
            serie.Border.Fill.Transparancy = transparency;             // Line transparency
            serie.Border.Width             = 1.0;                      // Line width
            if (serie.Marker != null)
            {
                serie.Marker.Border.Fill.Color = Color.Black;   // Marker border color
                serie.Marker.Border.Width      = 0.75;          // Marker border width
                serie.Marker.Size = 5;                          // Marker size
                // Marker fill color
                if (markerProperties.fillColor != Color.Transparent)
                {
                    serie.Marker.Fill.Color = markerProperties.fillColor;
                }
                else
                {
                    serie.Marker.Fill.Style = eFillStyle.NoFill;
                }
                // Marker style
                if (lineProperties.isMarkersEnabled)
                {
                    serie.Marker.Style = markerProperties.style;
                }
                else
                {
                    serie.Marker.Style = eMarkerStyle.None;
                }
                // Increment markers and lines indices
                ++indMarkers_[chartName];
                if (indMarkers_[chartName] >= markers.Count)
                {
                    indMarkers_[chartName] = 0;
                }
            }
            ++indLines_[chartName];
            if (indLines_[chartName] >= lines.Count)
            {
                indLines_[chartName] = 0;
            }
            // Legend
            serie.Header = dataName;
            // Shifting data locations
            pos.availablePosition.col = pos.availablePosition.col + 2;
            pos.length = Math.Max(pos.length, nData);
            int lastRowColumn = pos.availablePosition.row + pos.length;

            if (lastRowColumn > ChartPosition.lastRow)
            {
                ChartPosition.lastRow = lastRowColumn;
            }
        }