示例#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);
        }
示例#2
0
        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);
                        }
                    }
                }
            }
        }
示例#3
0
        private void SetWaterfallStructure(BarChartSeries seriesItem, Column dataColumn)
        {
            var  dataPoints = seriesItem.Elements <DataPoint>();
            var  labels     = seriesItem.FirstElement <DataLabels>();
            bool isFirstBar = dataColumn.Data[0] != null;

            if (!isFirstBar)
            {
                int       valueToHideInd = dataColumn.Data.IndexOf(dataColumn.Data.First(v => v != null));
                DataPoint dataPoint      = dataPoints.FirstOrDefault(p => p.Index != null && p.Index.Val != null && p.Index.Val.Value == valueToHideInd);
                dataPoint.RemoveAllChildren <ChartShapeProperties>();
                ChartShapeProperties chartShapeProperties = new ChartShapeProperties();
                chartShapeProperties.Append(new A.NoFill());
                dataPoint.Append(chartShapeProperties);
                DataLabel label = labels.Elements <DataLabel>().FirstOrDefault(p => p.Index != null && p.Index.Val != null && p.Index.Val.Value == valueToHideInd);
                if (label != null)
                {
                    label.FirstElement <ShowValue>().Val.Value = false;
                }
            }
            labels.FirstElement <ShowValue>().Val.Value = false;
        }
        protected void modificaChartData(string FormatoValori, string titoloSerie, out SeriesText seriesText1, out CategoryAxisData categoryAxisData1, out Values values1)
        {
            seriesText1 = new SeriesText();

            StringReference stringReference1 = new StringReference();
            Formula         formula1         = new Formula();

            formula1.Text = "Foglio1!$B$1";

            StringCache stringCache1 = new StringCache();
            PointCount  pointCount1  = new PointCount()
            {
                Val = (UInt32Value)1U
            };

            StringPoint stringPoint1 = new StringPoint()
            {
                Index = (UInt32Value)0U
            };
            NumericValue numericValue1 = new NumericValue();

            numericValue1.Text = titoloSerie;

            stringPoint1.Append(numericValue1);

            stringCache1.Append(pointCount1);
            stringCache1.Append(stringPoint1);

            stringReference1.Append(formula1);
            stringReference1.Append(stringCache1);

            seriesText1.Append(stringReference1);

            DataPoint dataPoint1 = new DataPoint();
            Index     index2     = new Index()
            {
                Val = (UInt32Value)2U
            };


            dataPoint1.Append(index2);

            //################################i testi ####################################
            categoryAxisData1 = new CategoryAxisData();

            StringReference stringReference2 = new StringReference();
            Formula         formula2         = new Formula();

            formula2.Text = string.Format("Foglio1!$A$2:$A${0}", valori.Count + 2);

            StringCache stringCache2 = new StringCache();
            UInt32Value nValori      = Convert.ToUInt32(valori.Count);

            PointCount pointCount2 = new PointCount()
            {
                Val = nValori
            };

            StringPoint[] stringPoints = new StringPoint[nValori];
            UInt32Value   n            = 0;

            foreach (KeyValuePair <string, double> item in valori)
            {
                stringPoints[n] = new StringPoint()
                {
                    Index = (UInt32Value)n
                };
                NumericValue numericValue2 = new NumericValue();
                numericValue2.Text = item.Key;
                stringPoints[n].Append(numericValue2);
                n += 1;
            }



            stringCache2.Append(pointCount2);
            for (int i = 0; i < n; i++)
            {
                stringCache2.Append(stringPoints[i]);
            }

            stringReference2.Append(formula2);
            stringReference2.Append(stringCache2);

            categoryAxisData1.Append(stringReference2);


            //################################i valori####################################

            values1 = new Values();

            NumberReference numberReference1 = new NumberReference();
            Formula         formula3         = new Formula();

            formula3.Text = string.Format("Foglio1!$B$2:$B${0}", valori.Count + 2);

            NumberingCache numberingCache1 = new NumberingCache();
            FormatCode     formatCode1     = new FormatCode();

            formatCode1.Text = FormatoValori; //<-----------------------------------------------------------
            PointCount pointCount3 = new PointCount()
            {
                Val = nValori
            };

            NumericPoint[] numericPoints = new NumericPoint[nValori];
            n = 0;
            foreach (KeyValuePair <string, double> item in valori)
            {
                numericPoints[n] = new NumericPoint()
                {
                    Index = (UInt32Value)n
                };
                NumericValue numericValue = new NumericValue();
                numericValue.Text = item.Value.ToString();
                numericValue.Text = numericValue.Text.Replace(",", "."); // devo forzare il formato americano
                numericPoints[n].Append(numericValue);
                n += 1;
            }



            numberingCache1.Append(formatCode1);
            numberingCache1.Append(pointCount3);
            for (int i = 0; i < n; i++)
            {
                numberingCache1.Append(numericPoints[i]);
            }



            numberReference1.Append(formula3);
            numberReference1.Append(numberingCache1);

            values1.Append(numberReference1);
        }
示例#5
0
        private void SetPropertiesFromLegend(OpenXmlCompositeElement seriesItem, Column dataColumn)
        {
            if (dataColumn.Legends.All(l => l == null))
            {
                return;
            }
            var dataPoints = seriesItem.Elements <DataPoint>();
            var labels     = seriesItem.FirstElement <DataLabels>();

            for (int rowNo = 0; rowNo < dataColumn.Data.Count; rowNo++)
            {
                if (dataColumn.Legends[rowNo] != null && dataColumn.Data[rowNo] != null)
                {
                    ShapeElement legend    = dataColumn.Legends[rowNo] as ShapeElement;
                    DataPoint    dataPoint = dataPoints.FirstOrDefault(p => p.Index != null && p.Index.Val != null && p.Index.Val.Value == rowNo);
                    if (legend != null) //KAJ: Actually always true if you have reached this line
                    {
                        if (dataPoint != null)
                        {
                            dataPoint.RemoveAllChildren <ChartShapeProperties>();
                            A.SolidFill          legendFill           = legend.Element.GetFill();
                            A.Outline            legendOutline        = legend.Element.GetOutline();
                            ChartShapeProperties chartShapeProperties = new ChartShapeProperties();
                            chartShapeProperties.Append(legendFill);
                            chartShapeProperties.Append(legendOutline);
                            dataPoint.Append(chartShapeProperties);
                        }
                        if (labels != null)
                        {
                            DataLabel label = labels.Elements <DataLabel>().FirstOrDefault(p => p.Index != null && p.Index.Val != null && p.Index.Val.Value == rowNo);
                            if (label != null)
                            {
                                TextProperties labelTextProperties = label.FirstElement <TextProperties>();
                                if (labelTextProperties == null)
                                {
                                    labelTextProperties = labels.FirstElement <TextProperties>().CloneNode(true) as TextProperties;
                                    label.Append(labelTextProperties);
                                }
                                NumberingFormat labelNumberingFormat = label.FirstElement <NumberingFormat>();
                                if (labelNumberingFormat == null)
                                {
                                    labelNumberingFormat = labels.FirstElement <NumberingFormat>().CloneNode(true) as NumberingFormat;
                                    label.Append(labelNumberingFormat);
                                }
                                A.Paragraph labelParagraph      = labelTextProperties.FirstElement <A.Paragraph>();
                                var         legendRunProperties = legend.Element.GetRunProperties();
                                labelParagraph.ParagraphProperties.RemoveAllChildren <A.DefaultRunProperties>();
                                List <OpenXmlElement> list = new List <OpenXmlElement>();
                                foreach (var item in legendRunProperties.ChildElements)
                                {
                                    list.Add(item.CloneNode(true));
                                }
                                var newLabelRunProperties = new A.DefaultRunProperties(list);
                                labelParagraph.ParagraphProperties.Append(newLabelRunProperties);
                                var labelShapeProperties = label.FirstElement <ChartShapeProperties>();
                                if (labelShapeProperties != null && labelShapeProperties.FirstElement <A.NoFill>() == null)
                                {
                                    label.RemoveAllChildren <ChartShapeProperties>();
                                }
                                A.SolidFill          legendFill           = legend.Element.GetFill();
                                ChartShapeProperties chartShapeProperties = new ChartShapeProperties();
                                chartShapeProperties.Append(legendFill);
                                label.Append(chartShapeProperties);
                            }
                        }
                    }
                }
            }
        }