示例#1
0
        public static void SetSeriesLineMarkerColor(this ExcelChart chart, int serieIdx, string color,
                                                    int makrkerSize = 7, eMarkerStyle markerStyle = eMarkerStyle.Circle)
        {
            ExcelScatterChartSerie serie = (ExcelScatterChartSerie)chart.Series[serieIdx];

            serie.LineColor       = ColorTranslator.FromHtml(color);
            serie.MarkerColor     = ColorTranslator.FromHtml(color);
            serie.MarkerLineColor = ColorTranslator.FromHtml(color);
            serie.MarkerSize      = makrkerSize;
            serie.Marker          = markerStyle;
        }
示例#2
0
        public void Scatter()
        {
            var ws   = _pck.Workbook.Worksheets.Add("Scatter");
            var chrt = ws.Drawings.AddChart("ScatterChart1", eChartType.XYScatterSmoothNoMarkers) as ExcelScatterChart;

            AddTestSerie(ws, chrt);
            // chrt.Series[0].Marker = eMarkerStyle.Diamond;
            chrt.To.Row    = 23;
            chrt.To.Column = 12;
            //chrt.Title.Text = "Header Text";
            var r1 = chrt.Title.RichText.Add("Header");

            r1.Bold = true;
            var r2 = chrt.Title.RichText.Add("  Text");

            r2.UnderLine = eUnderLineType.WavyHeavy;

            chrt.Title.Fill.Style        = eFillStyle.SolidFill;
            chrt.Title.Fill.Color        = Color.LightBlue;
            chrt.Title.Fill.Transparancy = 50;
            chrt.VaryColors = true;
            ExcelScatterChartSerie ser = chrt.Series[0] as ExcelScatterChartSerie;

            ser.DataLabel.Position     = eLabelPosition.Center;
            ser.DataLabel.ShowValue    = true;
            ser.DataLabel.ShowCategory = true;
            ser.DataLabel.Fill.Color   = Color.BlueViolet;
            ser.DataLabel.Font.Color   = Color.White;
            ser.DataLabel.Font.Italic  = true;
            ser.DataLabel.Font.SetFromFont(new Font("bookman old style", 8));
            Assert.IsTrue(chrt.ChartType == eChartType.XYScatterSmoothNoMarkers, "Invalid Charttype");
            chrt.Series[0].Header = "Test serie";
            chrt = ws.Drawings.AddChart("ScatterChart2", eChartType.XYScatterSmooth) as ExcelScatterChart;
            chrt.Series.Add("U19:U24", "V19:V24");

            chrt.From.Column     = 0;
            chrt.From.Row        = 25;
            chrt.To.Row          = 53;
            chrt.To.Column       = 12;
            chrt.Legend.Position = eLegendPosition.Bottom;

            ////chrt.Series[0].DataLabel.Position = eLabelPosition.Center;
            //Assert.IsTrue(chrt.ChartType == eChartType.XYScatter, "Invalid Charttype");
        }
示例#3
0
 private static void SetSerieDetails(DisplayResults.DisplayPage.DisplayTable.DisplayGraph.Series s, ExcelChartSerie serie)
 {
     serie.Header = s.name;
     if (!string.IsNullOrEmpty(s.colour))
     {
         Color sc = s.colour[0] == '#' ? Color.FromArgb(int.Parse("FF" + s.colour.Substring(1), System.Globalization.NumberStyles.HexNumber)) : Color.FromName(s.colour);
         serie.Fill.Color = sc;
         if (GetChartType(s) == eChartType.Line)
         {
             serie.Border.Fill.Color = sc;
         }
         if (serie is ExcelScatterChartSerie)
         {
             ExcelScatterChartSerie se = (serie as ExcelScatterChartSerie);
             se.Marker      = GetMarkerStyle(s);
             se.MarkerSize  = s.size;
             se.MarkerColor = sc;
         }
     }
 }
示例#4
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;
            }
        }