Exemple #1
0
        /// <summary>
        /// Distinct color for each bar.
        /// </summary>
        private DataPoint colorChartLines(uint lineIndex)
        {
            DataPoint dataPoint = new DataPoint();
            Index     index     = new Index()
            {
                Val = lineIndex
            };
            InvertIfNegative invertIfNegative3 = new InvertIfNegative()
            {
                Val = false
            };
            Bubble3D bubble3D1 = new Bubble3D()
            {
                Val = false
            };

            ChartShapeProperties chartShapeProperties = new ChartShapeProperties();

            SolidFill solidFill = new SolidFill();

            solidFill.SchemeColor = new SchemeColor()
            {
                Val = SchemeColorValues.Accent1
            };
            solidFill.RgbColorModelHex = new RgbColorModelHex()
            {
                Val = ColourValues[lineIndex]
            };

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

            outline.Append(new NoFill());
            outline.Append(new Round());
            chartShapeProperties.Append(solidFill);
            chartShapeProperties.Append(outline);
            chartShapeProperties.Append(new EffectList());

            dataPoint.Append(index);
            dataPoint.Append(chartShapeProperties);

            return(dataPoint);
        }
        private void FillSeriesDataPoints(OpenXmlCompositeElement seriesItem, Column dataColumn)
        {
            var seriesChartShapeProperties = seriesItem.FirstElement <ChartShapeProperties>();

            for (int rowNo = 0; rowNo < dataColumn.Data.Count; rowNo++)
            {
                if (dataColumn.Data[rowNo] != null)
                {
                    DataPoint dp = seriesItem.Elements <DataPoint>().FirstOrDefault(p => p.Index != null && p.Index.Val != null && p.Index.Val.Value == rowNo);
                    if (dp == null)
                    {
                        var dataPoint = new DataPoint();
                        DocumentFormat.OpenXml.Drawing.Charts.Index index = new DocumentFormat.OpenXml.Drawing.Charts.Index()
                        {
                            Val = new UInt32Value((uint)rowNo)
                        };
                        InvertIfNegative invertIfNegative = new InvertIfNegative()
                        {
                            Val = false
                        };
                        Bubble3D bubble3D = new Bubble3D()
                        {
                            Val = false
                        };
                        ChartShapeProperties chartShapeProperties = seriesChartShapeProperties == null ? new ChartShapeProperties() : (ChartShapeProperties)seriesChartShapeProperties.CloneNode(true);
                        dataPoint.Append(index);
                        dataPoint.Append(invertIfNegative);
                        dataPoint.Append(bubble3D);
                        dataPoint.Append(chartShapeProperties);
                        DataPoint lastDp = seriesItem.Elements <DataPoint>().LastOrDefault(p => p.Index != null && p.Index.Val != null && p.Index.Val.Value < rowNo);
                        if (lastDp != null)
                        {
                            seriesItem.InsertAfter(dataPoint, lastDp);
                        }
                        else
                        {
                            seriesItem.Append(dataPoint);
                        }
                    }
                }
            }
        }