/// <summary>
        /// Set display, width, color and fill of borders and data (line, bar etc.) in chart.
        /// </summary>
        public virtual ChartShapeProperties SetChartShapeProperties(OpenXmlCompositeElement chartSeries)

        {
            ChartShapeProperties chartShapeProperties = new ChartShapeProperties();
            Outline outline = new Outline()
            {
                Width = 28575, CapType = LineCapValues.Round
            };

            outline.Append(new NoFill());
            outline.Append(new Round());

            chartShapeProperties.Append(outline);
            chartShapeProperties.Append(new EffectList());

            chartSeries.Append(chartShapeProperties);

            return(chartShapeProperties);
        }
        /// <summary>
        /// Sets the color of the series using a solidcolor brush
        /// If a null brush is supplied any color is removed so the color will be automatic
        /// </summary>
        /// <param name="series">The series.</param>
        /// <param name="brush">The brush.</param>
        /// <exception cref="ArgumentNullException">series</exception>
        public static void UpdateSeriesMarkerBrush(this OpenXmlCompositeElement series, Brush brush)
        {
            if (series == null)
            {
                throw new ArgumentNullException("series");
            }

            var marker = series.Descendants <Marker>().FirstOrDefault();

            if (marker == null)
            {
                return;
            }

            var scb = brush as SolidColorBrush;

            if (scb == null)
            {
                return;
            }

            // clear down and start again
            marker.RemoveAllChildren();

            var chartShapeProperties = new ChartShapeProperties();

            SolidFill solidFill = new SolidFill();

            StringBuilder hexString = new StringBuilder();

            hexString.Append(scb.Color.R.ToString("X"));
            hexString.Append(scb.Color.G.ToString("X"));
            hexString.Append(scb.Color.B.ToString("X"));

            RgbColorModelHex hexColour = new RgbColorModelHex()
            {
                Val = hexString.ToString()
            };

            var outlineNoFill = new Outline();

            outlineNoFill.Append(new NoFill());

            solidFill.Append(hexColour);
            chartShapeProperties.Append(solidFill);
            chartShapeProperties.Append(outlineNoFill);
            marker.Append(chartShapeProperties);
        }
Exemple #3
0
        /// <summary>
        /// Updates the chart.
        /// </summary>
        /// <param name="chart">The chart.</param>
        /// <param name="sheetName">Name of the sheet.</param>
        protected override void UpdateChart(OpenXmlCompositeElement chart, string sheetName)
        {
            if (chart != null)
            {
                chart.RemoveAllChildren <ScatterChartSeries>();
                ScatterChartSeries scatterChartSeries = chart.AppendChild <ScatterChartSeries>(new ScatterChartSeries());

                Outline outline = new Outline()
                {
                    Width = 28575
                };
                NoFill noFill = new NoFill();
                outline.Append(noFill);
                scatterChartSeries.ChartShapeProperties = new ChartShapeProperties(outline);

                UpdateSeriesText(sheetName, scatterChartSeries, "B", 1, chartData.yColumnName);

                XValues xValues = scatterChartSeries.AppendChild <XValues>(new XValues());
                YValues yValues = scatterChartSeries.AppendChild <YValues>(new YValues());

                NumberReference referenceX = CreateNumberReference(xValues, sheetName + "!$A$2:$A$" + (chartData.Count + 1).ToString());
                NumberReference referenceY = CreateNumberReference(yValues, sheetName + "!$B$2:$B$" + (chartData.Count + 1).ToString());

                NumberingCache ncX;
                PointCount     ptXCount;
                NumberingCache ncY;
                PointCount     ptYCount;

                SetNumberingCache(referenceX, out ncX, out ptXCount);
                SetNumberingCache(referenceY, out ncY, out ptYCount);

                int rowIndex = 0;

                foreach (var xToY in chartData.xValToYValMap)
                {
                    AddNumericPoint(ncX, ptXCount, rowIndex, xToY.Key.ToString());
                    AddNumericPoint(ncY, ptYCount, rowIndex, xToY.Value.ToString());
                    rowIndex += 1;
                }
            }
        }
        public Outline Build()
        {
            var outline = new Outline();

            switch (this.Options.FillType)
            {
            case FillTypes.NoFill:
                outline.Append(new NoFill());

                break;

            case FillTypes.Solid:
                var solidFill = new SolidFill();

                if (this.Options.SchemaColorOptions != null)
                {
                    var schemaColorBuilder = new SchemaColorBuilder(this.Options.SchemaColorOptions);

                    solidFill.SchemeColor = schemaColorBuilder.Build();
                }

                outline.Append(solidFill);

                break;

            case FillTypes.Gradient:
                break;
            }

            if (this.Options.JoinType.HasValue)
            {
                switch (this.Options.JoinType)
                {
                case JoinTypes.Round:
                    outline.Append(new Round());
                    break;

                case JoinTypes.Bevel:
                    outline.Append(new Bevel());
                    break;

                case JoinTypes.Miter:
                    outline.Append(new Miter()
                    {
                        Limit = 800000
                    });
                    break;
                }
            }

            if (this.Options.Width.HasValue)
            {
                outline.Width = Convert.ToInt32(this.Options.Width * 12700);
            }

            if (this.Options.LineCap.HasValue)
            {
                outline.CapType = this.Options.LineCap;
            }

            if (this.Options.CompoundLine.HasValue)
            {
                outline.CompoundLineType = this.Options.CompoundLine;
            }

            if (this.Options.PenAlignment.HasValue)
            {
                outline.Alignment = this.Options.PenAlignment;
            }

            return(outline);
        }
        /// <summary>
        /// Design settings for Y axis.
        /// </summary>
        public virtual ValueAxis SetValueAxis(PlotArea plotArea)
        {
            // Postavljanje Gridline-a.
            MajorGridlines       majorGridlines       = new MajorGridlines();
            ChartShapeProperties chartShapeProperties = new ChartShapeProperties();
            Outline     outline     = new Outline();
            SolidFill   solidFill   = new SolidFill();
            SchemeColor schemeColor = new SchemeColor()
            {
                Val = SchemeColorValues.Accent1
            };
            Alpha alpha = new Alpha()
            {
                Val = 10000
            };

            schemeColor.Append(alpha);
            solidFill.Append(schemeColor);
            outline.Append(solidFill);
            chartShapeProperties.Append(outline);
            majorGridlines.Append(chartShapeProperties);

            var valueAxis = plotArea.AppendChild <ValueAxis>(new ValueAxis(
                                                                 new AxisId()
            {
                Val = new UInt32Value(48672768u)
            },
                                                                 new Scaling(new Orientation()
            {
                Val = new EnumValue <DocumentFormat.OpenXml.Drawing.Charts.OrientationValues>(
                    DocumentFormat.OpenXml.Drawing.Charts.OrientationValues.MinMax)
            }),
                                                                 new Delete()
            {
                Val = !ChartProperties.AxisY
            },
                                                                 new AxisPosition()
            {
                Val = new EnumValue <AxisPositionValues>(AxisPositionValues.Left)
            },
                                                                 majorGridlines,
                                                                 SetTitle(ChartProperties.AxisYTitle),
                                                                 new NumberingFormat()
            {
                FormatCode   = ChartProperties.AxisYFormatCode,
                SourceLinked = new BooleanValue(true)
            },
                                                                 new MajorTickMark()
            {
                Val = TickMarkValues.None
            },
                                                                 new MinorTickMark()
            {
                Val = TickMarkValues.None
            },
                                                                 new TickLabelPosition()
            {
                Val = new EnumValue <TickLabelPositionValues>
                          (TickLabelPositionValues.NextTo)
            }, new CrossingAxis()
            {
                Val = new UInt32Value(48650112U)
            },
                                                                 new Crosses()
            {
                Val = new EnumValue <CrossesValues>(CrossesValues.AutoZero)
            },
                                                                 new CrossBetween()
            {
                Val = new EnumValue <CrossBetweenValues>(CrossBetweenValues.Between)
            }));

            if (ChartProperties.AxisYFormatCategory == "Time")
            {
                valueAxis.Append(new MajorUnit()
                {
                    Val = getMajorUnitFromSeconds((int)yAxisValue)
                });
            }

            return(valueAxis);
        }