예제 #1
0
        public static void ReplaceChart(Charts.Chart chart, Data.DataTable table)
        {
            var plotArea = chart.Descendants <Charts.PlotArea>().SingleEx();
            var series   = plotArea.Descendants <OpenXmlCompositeElement>().Where(a => a.LocalName == "ser").ToList();

            SynchronizeNodes(series, table.Rows.Cast <Data.DataRow>().ToList(),
                             (ser, row, i, isCloned) =>
            {
                if (isCloned)
                {
                    ser.Descendants <Drawing.SchemeColor>().ToList().ForEach(f => f.Remove());
                }

                BindSerie(ser, row, i);
            });
        }
예제 #2
0
    public static void ReplaceChart(Charts.Chart chart, Data.DataTable table, string titleForError)
    {
        var plotArea = chart.Descendants <Charts.PlotArea>().SingleEx();
        var series   = plotArea.Descendants <OpenXmlCompositeElement>().Where(a => a.LocalName == "ser").ToList();

        var rows = table.Rows.Cast <Data.DataRow>().ToList();

        SynchronizeNodes(series, table.Columns.Cast <Data.DataColumn>().Skip(1).ToList(),
                         (ser, col, i, isCloned) =>
        {
            if (!ReflectionTools.IsNumber(col.DataType) && !ReflectionTools.IsDate(col.DataType))
            {
                throw new InvalidOperationException($"Unable to bind the chart serie with the column '{col.ColumnName}' of type '{col.DataType.TypeName()}'. Consider using 'Pivot(colY, colX, colValue)' in the Alternative Text of your chart like this:\n" + titleForError.Lines().FirstEx() + "\nPivot(0,1,2)");
            }

            if (isCloned)
            {
                ser.Descendants <Drawing.SchemeColor>().ToList().ForEach(f => f.Remove());
            }

            BindSerie(ser, rows, col, i);
        });
    }