Index: src/main/java/org/xwiki/chart/internal/source/InlineDataSourceFactory.java
===================================================================
--- src/main/java/org/xwiki/chart/internal/source/InlineDataSourceFactory.java	(revision 0)
+++ src/main/java/org/xwiki/chart/internal/source/InlineDataSourceFactory.java	(revision 0)
@@ -0,0 +1,92 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ */
+
+package org.xwiki.chart.internal.source;
+
+import java.io.StringReader;
+import java.util.List;
+import java.util.Map;
+
+import org.xwiki.component.annotation.Component;
+import org.xwiki.component.manager.ComponentLookupException;
+import org.xwiki.component.manager.ComponentManager;
+import org.xwiki.component.phase.Composable;
+import org.xwiki.chart.ChartGeneratorException;
+import org.xwiki.chart.source.DataSource;
+import org.xwiki.chart.source.DataSourceFactory;
+import org.xwiki.rendering.block.Block;
+import org.xwiki.rendering.block.XDOM;
+import org.xwiki.rendering.macro.chart.ChartMacroParameters;
+import org.xwiki.rendering.parser.ParseException;
+import org.xwiki.rendering.parser.Parser;
+import org.xwiki.rendering.transformation.MacroTransformationContext;
+
+/**
+ * This gets a datasource by parsing the contents of the macro's body.
+ * 
+ * @version $Id: $
+ * @since 1.9
+ */
+
+@Component("inline")
+public final class InlineDataSourceFactory implements DataSourceFactory, Composable
+{
+    /**
+     * The component manager needed for instantiating the datasource factory.
+     */
+    private ComponentManager componentManager;
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see Composable#compose(ComponentManager)
+     */
+    @Override
+    public void compose(ComponentManager componentManager)
+    {
+        this.componentManager = componentManager;
+    }
+
+    /**
+     * {@inheritDoc} 
+     * @see org.xwiki.chart.source.DataSourceFactory#create(Map)
+     */
+    @Override
+    public DataSource create(Map<String, Object> params) throws ChartGeneratorException
+    {
+        MacroTransformationContext context = (MacroTransformationContext) params.get(ChartMacroParameters.CONTEXT);
+        String content = (String) params.get(ChartMacroParameters.CONTENT);
+        
+        Parser parser = null;
+        try {
+            parser = (Parser) componentManager.lookup(Parser.class, context.getSyntax().toIdString());
+            List<Block> titleBlocks = parser.parse(new StringReader(content)).getChildren();
+            XDOM xdom = new XDOM(titleBlocks);
+            params.put(ChartMacroParameters.XDOM_TREE, xdom);
+        } catch (ParseException e) {
+            throw new ChartGeneratorException("Failed to parse the macro's body.", e);
+        } catch (ComponentLookupException e) {
+            throw new ChartGeneratorException("Failed to find source parser.", e);
+        }
+        
+        return new XdomDataSource(params);
+    }
+}
Index: src/main/java/org/xwiki/chart/internal/source/XdomDataSource.java
===================================================================
--- src/main/java/org/xwiki/chart/internal/source/XdomDataSource.java	(revision 0)
+++ src/main/java/org/xwiki/chart/internal/source/XdomDataSource.java	(revision 0)
@@ -0,0 +1,494 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ */
+package org.xwiki.chart.internal.source;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.List;
+import java.util.Map;
+
+import org.xwiki.chart.ChartGeneratorException;
+import org.xwiki.chart.source.DataSource;
+import org.xwiki.chart.source.DefaultDataSource;
+import org.xwiki.rendering.block.SpecialSymbolBlock;
+import org.xwiki.rendering.block.TableCellBlock;
+import org.xwiki.rendering.block.Block;
+import org.xwiki.rendering.block.SpaceBlock;
+import org.xwiki.rendering.block.TableBlock;
+import org.xwiki.rendering.block.TableRowBlock;
+import org.xwiki.rendering.block.WordBlock;
+import org.xwiki.rendering.block.XDOM;
+
+/**
+ * Allows reading data from table within a WIKI 2.0 document.
+ * 
+ * @version $Id: $
+ * @since 1.9
+ */
+public class XdomDataSource extends DefaultDataSource  implements DataSource
+{
+    /** The parameter which designates the table number.  */
+    private static final String TABLE_NUMBER = "table_number";
+
+    /** The parameter which designates the range within a table.  */
+    private static final String RANGE = "range";
+
+    /** The parameter which specifies whether the first table row is a header.  */
+    private static final String HAS_HEADER_ROW = "has_header_row";
+
+    /** The parameter which specifies whether the first table column is a header.  */
+    private static final String HAS_HEADER_COLUMN = "has_header_column";
+
+    /** The parameter which specifies the decimal symbol used for parsing numbers.  */
+    private static final String DECIMAL_SYMBOL = "decimal_symbol";
+
+    /** The parameter which specifies whether to ignore the letters when parsing numbers.  */
+    private static final String IGNORE_ALPHA = "ignore_alpha";
+
+    /** The comma selector.  */
+    private static final String COMMA_SELECTOR = "comma";
+
+    /** The period selector. */
+    private static final String PERIOD_SELECTOR = "period";
+
+    /** The default table to be selected when there's no one specified. */
+    private static final int DEFAULT_TABLE_NUMBER = 0;
+
+    /** The default range. */
+    private static final String DEFAULT_RANGE = "*";
+
+    /** By default, whether to assume the table has a header row. */
+    private static final boolean DEFAULT_HAS_HEADER_ROW = true;
+
+    /** By default, whether to assume the table has a header column. */
+    private static final boolean DEFAULT_HAS_HEADER_COLUMN = true;
+
+    /** Whether to ignore the letters, by default, when parsing the numbers. */
+    private static final boolean DEFAULT_IGNORE_ALPHA = false;
+
+    /** The comma character. */
+    private static final char COMMA = ',';
+
+    /** The period character. */
+    private static final char PERIOD = '.';
+
+    /** The range separator. */
+    private static final char RANGE_SEP = '-';
+
+    /** The first column to be taken into account. */
+    private int startColumn = -1;
+
+    /** The last column to be taken into account. */
+    private int endColumn = -1;
+
+    /** The first row to be taken into account. */
+    private int startRow = -1;
+
+    /** The last row to be taken into account. */
+    private int endRow = -1;
+
+    /** The index of the header column. */
+    private int headerColumnIndex = -1;
+
+    /** The index of the header row. */
+    private int headerRowIndex = -1;
+
+    /** The decimal symbol. */
+    private char decimalSymbol = PERIOD;
+
+    /** The digit grouping symbol. */
+    private char digitGroupingSymbol = COMMA;
+
+    /** Whether to ignore the letters, by default, when parsing the numbers. */
+    private boolean ignoreAlpha;
+
+    /**
+     * The constructor for this class.
+     * @param params the parameters for generating the data source
+     * @throws ChartGeneratorException in case of failure.
+     */
+    public XdomDataSource(Map<String, Object> params) throws ChartGeneratorException
+    {
+        XDOM xdom = (XDOM) params.get("xdom");
+        
+        String n = (String) params.get(TABLE_NUMBER);
+        int number;
+        if (n != null) {
+            try {
+                number = Integer.parseInt(n);
+            } catch (NumberFormatException e) {
+                throw new ChartGeneratorException(
+                    "Invalid argument 'table_number' for parameter source: integer value expected");
+            }
+        } else {
+            number = DEFAULT_TABLE_NUMBER;
+        }
+
+        String range = (String) params.get(RANGE);
+        if (range == null) {
+            range = DEFAULT_RANGE;
+        }
+
+        String hhr = (String) params.get(HAS_HEADER_ROW);
+        boolean hasHeaderRow;
+        if (hhr != null) {
+            hasHeaderRow = hhr.equalsIgnoreCase(Boolean.TRUE.toString());
+        } else {
+            hasHeaderRow = DEFAULT_HAS_HEADER_ROW;
+        }
+
+        String hhc = (String) params.get(HAS_HEADER_COLUMN);
+        boolean hasHeaderColumn;
+        if (hhc != null) {
+            hasHeaderColumn = hhc.equalsIgnoreCase(Boolean.TRUE.toString());
+        } else {
+            hasHeaderColumn = DEFAULT_HAS_HEADER_COLUMN;
+        }
+
+        String decimal = (String) params.get(DECIMAL_SYMBOL);
+
+        String ia = (String) params.get(IGNORE_ALPHA);
+        boolean ignoreLetters;
+        if (ia != null) {
+            ignoreLetters = ia.equals("true");
+        } else {
+            ignoreLetters = DEFAULT_IGNORE_ALPHA;
+        }
+
+        init(xdom, number, range, hasHeaderRow, hasHeaderColumn, decimal, ignoreLetters);
+    }
+
+    /**
+     * Performs initialization of the data source.
+     * @param xdom the XDOM tree from which data is going to be read
+     * @param tableNumber the table from the XDOM tree which contains the actual data
+     * @param range the range from the table which we take into account
+     * @param hasHeaderRow whether the table has a header row
+     * @param hasHeaderColumn whether the table has a column row
+     * @param decimalSymbolSelector the decimal symbol
+     * @param ignoreAlpha whether to ignore the letters when parsing the numbers 
+     * @throws ChartGeneratorException in case of error
+     */
+    private void init(XDOM xdom, int tableNumber, String range, boolean hasHeaderRow, boolean hasHeaderColumn,
+        String decimalSymbolSelector, boolean ignoreAlpha) throws ChartGeneratorException
+    {
+        try {
+            List<TableBlock> tables = xdom.getChildrenByType(TableBlock.class, true);
+            TableBlock table = tables.get(tableNumber);
+
+            parseRange(range, hasHeaderRow, hasHeaderColumn, table);
+            setDecimalSymbol(decimalSymbolSelector);
+            this.ignoreAlpha = ignoreAlpha;
+            makeDataMatrix(table);
+            makeHeaders(table);
+        } catch (NumberFormatException e) {
+            throw new ChartGeneratorException(e);
+        }
+    }
+
+    /** 
+     * Sets up the decimal and the digit grouping symbols.
+     * @param decimalSymbolSelector the decimal symbol, encoded as a string
+     * @throws ChartGeneratorException in case of invalid decimal symbol
+     */
+    private void setDecimalSymbol(String decimalSymbolSelector) throws ChartGeneratorException
+    {
+        if (decimalSymbolSelector != null) {
+            if (decimalSymbolSelector.equals(COMMA_SELECTOR)) {
+                decimalSymbol = COMMA;
+                digitGroupingSymbol = PERIOD;
+            } else if (decimalSymbolSelector.equals(PERIOD_SELECTOR)) {
+                decimalSymbol = PERIOD;
+                digitGroupingSymbol = COMMA;
+            } else {
+                throw new ChartGeneratorException("Invalid argument " + DECIMAL_SYMBOL + " for parameter source:"
+                    + "comma or period expected; found: " + decimalSymbolSelector);
+            }
+        }
+    }
+
+    /**
+     * Builds a matrix for storing the data from the source.
+     * @param t the table from which to extract the data
+     */
+    private void makeDataMatrix(TableBlock t)
+    {
+        this.data = new Number[endRow - startRow + 1][endColumn - startColumn + 1];
+        for (int row = startRow; row <= endRow; ++row) {
+            for (int col = startColumn; col <= endColumn; ++col) {
+                try {
+                    data[row - startRow][col - startColumn] = toNumber(getData(t, row, col));
+                } catch (Exception e) {
+                    data[row - startRow][col - startColumn] = null;
+                }
+            }
+        }
+    }
+
+    /**
+     * Looks for headers in the specified table.
+     * @param t the table to scan
+     */
+    private void makeHeaders(TableBlock t)
+    {
+        if (headerColumnIndex >= 0) {
+            headerColumn = new String[endRow - startRow + 1];
+            for (int row = startRow; row <= endRow; row++) {
+                try {
+                    headerColumn[row - startRow] = getData(t, row, headerColumnIndex);
+                } catch (Exception e) {
+                    headerColumn[row - startRow] = "";
+                }
+            }
+        }
+        if (headerRowIndex >= 0) {
+            headerRow = new String[endColumn - startColumn + 1];
+            for (int col = startColumn; col <= endColumn; col++) {
+                try {
+                    headerRow[col - startColumn] = getData(t, headerRowIndex, col);
+                } catch (Exception ex) {
+                    headerRow[col - startColumn] = "";
+                }
+            }
+        }
+    }
+
+    /**
+     * @param string the string to be parsed
+     * @return the number resulted from parsing the string
+     * @throws NumberFormatException in case the string doesn't represent a number
+     */
+    private Number toNumber(String string) throws NumberFormatException
+    {
+        String preparsedString = preparseNumber(string);
+        try {
+            return new Long(preparsedString);
+        } catch (NumberFormatException e1) { 
+            // go on with the next attempt
+        }
+        try {
+            return new Double(preparsedString);
+        } catch (NumberFormatException e2) { 
+            // go on with the next attempt
+        }
+        try {
+            return new BigInteger(preparsedString);
+        } catch (NumberFormatException e3) { 
+            // go on with the next attempt
+        }
+        try {
+            return new BigDecimal(preparsedString);
+        } catch (NumberFormatException e4) { 
+            // give up
+        }
+        
+        return null;
+    }
+
+    /**
+     * @param string the string to be preparsed
+     * @return a string from which all the useless characters for parsing 
+     * the number (like spaces, for example) are removed
+     */
+    private String preparseNumber(String string) 
+    {
+        String str =  string.trim();
+        StringBuffer result = new StringBuffer();
+        
+        for (int index = 0; index < str.length(); index++) {
+            char character = str.charAt(index);
+            result.append(preparseChar(character, index, str, result.length() == 0));
+        }
+        return result.toString();
+    }
+
+    /**
+     * Preparses a single character (see {@link #preparseNumber(String)} for details).
+     * @param character the character to be inspected
+     * @param index its position in the containing string 
+     * @param string the containing string
+     * @param firstDigit whether the first digit of the number hasn't been parsed yet
+     * @return a preparsed character or an empty char, in case the given character has to be ignored
+     */
+    private char preparseChar(Character character, int index, String string, boolean firstDigit)
+    {
+        final String invalidCharacter = "Invalid character: ";
+
+        if (Character.isDigit(character)) {
+            return character;
+        } 
+        if (character == decimalSymbol) {
+            return '.';
+        } 
+        if (this.ignoreAlpha || isDigitGroupingCharacter(character, firstDigit, index, string)) {
+            // ignore
+            return (Character) null;
+        }
+        if ((character == '-' || character == '+') && index == 0) {
+            return character;
+        } 
+        throw new NumberFormatException(invalidCharacter + character);
+    }
+
+   /**
+    * @param character the character to be inspected
+    * @param index its position in the containing string 
+    * @param string the containing string
+    * @param firstDigit whether the first digit of the number hasn't been parsed yet
+    * @return <b>true</b>, if the given character is a digit grouping symbol, <b>false</b> otherwise. 
+    */
+    private boolean isDigitGroupingCharacter(Character character, 
+        boolean firstDigit, int index, String string) 
+    {
+        if (character != this.digitGroupingSymbol) {
+            return false;
+        }
+        return !firstDigit 
+            && index < string.length() - 1 
+            && Character.isDigit(string.charAt(index - 1))
+            && Character.isDigit(string.charAt(index + 1));
+    }
+    /**
+     * Valid string formats: Xm-Yn => rectangular range X-Y => whole columns range m-n => whole rows range * => enire
+     * table Where X, Y are Uppercase letters, m, n are numbers First column is A, first row is 1.
+     * @param range the table range which holds the actual data 
+     * @param hasHeaderRow whether the table has a header row
+     * @param hasHeaderColumn whether the table has a header column
+     * @param table the table Block from which to get the data
+     * @throws ChartGeneratorException in case of invalid range specied
+     */
+    private void parseRange(String range, boolean hasHeaderRow, boolean hasHeaderColumn, TableBlock table)
+        throws ChartGeneratorException
+    {
+        final String letterPattern = "[A-Z]";
+        final String numberPattern = "[0-9]+";
+        final String dataSourceError = "Data source cannot contain only a header"; 
+        
+        if (range.matches(letterPattern + numberPattern + RANGE_SEP + letterPattern + numberPattern)) {
+            startColumn = range.charAt(0) - 'A';
+            startRow = Integer.parseInt(range.substring(1, range.indexOf(RANGE_SEP))) - 1;
+            endColumn = range.charAt(range.indexOf(RANGE_SEP) + 1) - 'A';
+            endRow = Integer.parseInt(range.substring(range.indexOf(RANGE_SEP) + 2)) - 1;
+        } else if (range.matches(letterPattern + RANGE_SEP + letterPattern)) {
+            startColumn = range.charAt(0) - 'A';
+            startRow = 0;
+            endColumn = range.charAt(range.indexOf(RANGE_SEP) + 1) - 'A';
+            endRow = getTableRowCount(table);
+        } else if (range.matches(numberPattern + RANGE_SEP + numberPattern)) {
+            startColumn = 0;
+            startRow = Integer.parseInt(range.substring(0, range.indexOf(RANGE_SEP))) - 1;
+            endColumn = getTableColumnCount(table);
+            endRow = Integer.parseInt(range.substring(range.indexOf(RANGE_SEP) + 1)) - 1;
+        } else if (range.equals(DEFAULT_RANGE)) {
+            startColumn = 0;
+            startRow = 0;
+            endColumn = getTableColumnCount(table) - 1;
+            endRow = getTableRowCount(table) - 1;
+        }
+        if (hasHeaderColumn) {
+            this.headerColumnIndex = startColumn++;
+            if (startColumn > endColumn) {
+                throw new ChartGeneratorException(dataSourceError);
+            }
+        }
+        if (hasHeaderRow) {
+            this.headerRowIndex = startRow++;
+            if (startRow > endRow) {
+                throw new ChartGeneratorException(dataSourceError);
+            }
+        }
+    }
+
+    /**
+     * 
+     * @param table a table Block to inspect
+     * @return the maximum number of columns from the given table
+     */
+    public static int getTableColumnCount(TableBlock table)
+    {
+        int maxColumns = 0;
+        for (Block rowBlock : table.getChildren()) {
+            if (rowBlock instanceof TableRowBlock) {
+                int columns = 0;
+                for (Block cellBlock : rowBlock.getChildren()) {
+                    if (cellBlock instanceof TableCellBlock) {
+                        ++columns;
+                    }
+                }
+                if (columns > maxColumns) {
+                    maxColumns = columns;
+                }
+            }
+        }
+        
+        return maxColumns;
+    }
+
+    /**
+     * @param table a table Block to inspect
+     * @return the number of rows from the given table
+     */
+    public static int getTableRowCount(TableBlock table) 
+    {
+        int rows = 0;
+        for (Block rowBlock : table.getChildren()) {
+            if (rowBlock instanceof TableRowBlock) {
+                ++rows;
+            }
+        }
+        
+        return rows;
+    }
+    
+    /**
+     * @param table from which we need to extract data
+     * @param row the specified row
+     * @param column the specified column
+     * @return the data extracted from the table
+     */
+    private String getData(TableBlock table, int row, int column) {
+        Block block = table.getChildren().get(row).getChildren().get(column);
+        if (block instanceof WordBlock) {
+            return ((WordBlock) block).getWord();
+        }
+
+        StringBuilder result = new StringBuilder();
+        boolean encounteredDecimal = false;
+        
+        for (Block item : block.getChildren()) {
+            if (item instanceof WordBlock) {
+                result.append(((WordBlock) item).getWord());
+            } else if (item instanceof SpaceBlock) {
+                result.append(" ");
+            } else if (item instanceof SpecialSymbolBlock) { 
+                char symbol = ((SpecialSymbolBlock) item).getSymbol();
+                if (symbol == '-') {
+                    result.append('-');
+                } else if (symbol == this.decimalSymbol && !encounteredDecimal) {
+                    result.append(this.decimalSymbol);
+                    encounteredDecimal = true;
+                }
+            }
+        }
+        
+        return result.toString();
+    }
+}
Index: src/main/java/org/xwiki/chart/internal/source/XdomDataSourceFactory.java
===================================================================
--- src/main/java/org/xwiki/chart/internal/source/XdomDataSourceFactory.java	(revision 0)
+++ src/main/java/org/xwiki/chart/internal/source/XdomDataSourceFactory.java	(revision 0)
@@ -0,0 +1,83 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ */
+package org.xwiki.chart.internal.source;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang.StringUtils;
+import org.xwiki.chart.ChartGeneratorException;
+import org.xwiki.chart.source.DataSource;
+import org.xwiki.chart.source.DataSourceFactory;
+import org.xwiki.component.annotation.Component;
+import org.xwiki.component.annotation.Requirement;
+import org.xwiki.rendering.block.Block;
+import org.xwiki.rendering.block.XDOM;
+import org.xwiki.rendering.macro.Macro;
+import org.xwiki.rendering.macro.MacroExecutionException;
+import org.xwiki.rendering.macro.chart.ChartMacroParameters;
+import org.xwiki.rendering.macro.include.IncludeMacroParameters;
+import org.xwiki.rendering.macro.include.IncludeMacroParameters.Context;
+import org.xwiki.rendering.transformation.MacroTransformationContext;
+
+/**
+ * Responsible for creating a data source from an XDOM tree.
+ * 
+ * @version $Id: $
+ * @since 1.9
+ */
+
+@Component("xdom")
+public final class XdomDataSourceFactory implements DataSourceFactory
+{
+    /**
+     * The Include macro, needed for getting the XDOM tree from a specific document.
+     */
+    @Requirement("include")
+    protected Macro<IncludeMacroParameters> includeMacro;
+    
+    /**
+     * {@inheritDoc} 
+     * @see org.xwiki.chart.source.DataSourceFactory#create(Map)
+     */
+    @Override
+    public DataSource create(Map<String, Object> params) throws ChartGeneratorException
+    {
+        String documentName = (String) params.get(ChartMacroParameters.DOCUMENT);
+        if (StringUtils.isEmpty(documentName)) {
+            MacroTransformationContext context = (MacroTransformationContext) params.get(ChartMacroParameters.CONTEXT);
+            params.put(ChartMacroParameters.XDOM_TREE, context.getXDOM());
+        } else {
+            IncludeMacroParameters parameters = new IncludeMacroParameters();
+            parameters.setDocument(documentName);
+            parameters.setContext(Context.CURRENT);
+            List<Block> result;
+            try {
+                result = this.includeMacro.execute(parameters, null, null);
+            } catch (MacroExecutionException e) {
+                throw new ChartGeneratorException("Failed to parse included page [" + documentName + "]", e);
+            }
+            XDOM xdom = new XDOM(result);
+            params.put(ChartMacroParameters.XDOM_TREE, xdom);
+        }
+        return new XdomDataSource(params);
+    }
+}
Index: src/main/java/org/xwiki/rendering/internal/macro/chart/ChartMacro.java
===================================================================
--- src/main/java/org/xwiki/rendering/internal/macro/chart/ChartMacro.java	(revision 0)
+++ src/main/java/org/xwiki/rendering/internal/macro/chart/ChartMacro.java	(revision 0)
@@ -0,0 +1,196 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.xwiki.rendering.internal.macro.chart;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.xwiki.bridge.DocumentAccessBridge;
+import org.xwiki.chart.ChartGenerator;
+import org.xwiki.component.annotation.Component;
+import org.xwiki.component.annotation.Requirement;
+import org.xwiki.component.manager.ComponentLookupException;
+import org.xwiki.component.manager.ComponentManager;
+import org.xwiki.component.phase.Composable;
+import org.xwiki.container.Container;
+import org.xwiki.chart.source.DataSource;
+import org.xwiki.chart.source.DataSourceFactory;
+import org.xwiki.rendering.block.Block;
+import org.xwiki.rendering.block.ImageBlock;
+import org.xwiki.rendering.block.LinkBlock;
+import org.xwiki.rendering.internal.util.EnumConverter;
+import org.xwiki.rendering.listener.Link;
+import org.xwiki.rendering.listener.LinkType;
+import org.xwiki.rendering.listener.URLImage;
+import org.xwiki.rendering.macro.AbstractMacro;
+import org.xwiki.rendering.macro.MacroExecutionException;
+import org.xwiki.rendering.macro.chart.ChartMacroParameters;
+import org.xwiki.rendering.macro.chart.ChartMacroParameters.ChartType;
+import org.xwiki.rendering.macro.descriptor.DefaultMacroDescriptor;
+import org.xwiki.rendering.transformation.MacroTransformationContext;
+
+/**
+ * Displays a chart.
+ * 
+ * @version $Id: $
+ * @since 1.9
+ */
+
+@Component("chart")
+public class ChartMacro extends AbstractMacro<ChartMacroParameters> implements Composable
+{
+    /**
+     * The description of the macro.
+     */
+    private static final String DESCRIPTION = "Displays a chart generated from miscelaneous data sources.";
+    
+    /**
+     * The name of the directory holding the generated charts.
+     */
+    private static final String CHARTS_DIR_NAME = "charts";
+
+    /**
+     * Used for building the actual chart.
+     */
+    @Requirement
+    protected ChartGenerator chartGenerator;
+
+    /**
+     * Used for getting web URLs from specific filenames.
+     */
+    @Requirement
+    protected DocumentAccessBridge documentAccessBridge;
+   
+    /** A directory used for storing temporary files. */
+    protected File tempDir;
+    
+    /**
+     * The component manager needed for instantiating the datasource factory.
+     */
+    private ComponentManager componentManager;
+    
+    /** 
+     * The web container of the current module. 
+     */
+    @Requirement
+    private Container container;
+
+    /**
+     * Create and initialize the descriptor of the macro.
+     */
+    public ChartMacro()
+    {
+        super(new DefaultMacroDescriptor(DESCRIPTION, ChartMacroParameters.class));
+        registerConverter(new EnumConverter(ChartType.class), ChartType.class);
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see Composable#compose(ComponentManager)
+     */
+    @Override
+    public void compose(ComponentManager componentManager)
+    {
+        this.componentManager = componentManager;
+    }
+    
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.xwiki.rendering.macro.Macro#execute(Object, String, MacroTransformationContext)
+     */
+    public List<Block> execute(ChartMacroParameters parameters, String content, MacroTransformationContext context) 
+        throws MacroExecutionException
+    {
+        String imageLocation;
+        try {
+            initTempDir();
+            Map<String, Object> parametersMap = parameters.getParametersMap();
+            parametersMap.put("context", context);
+            parametersMap.put("content", content);
+            File chartImageFile = generateChart(parametersMap);
+
+            imageLocation = this.documentAccessBridge.getURL(null, "charting", null, null) 
+                + "/" + chartImageFile.getName();
+        } catch (Exception e) {
+            throw new MacroExecutionException(e.getMessage(), e);
+        }
+        String title = parameters.getTitle();
+        
+
+        Link link = new Link();
+        link.setReference(imageLocation);
+        link.setType(LinkType.URI);
+        ImageBlock imageBlock = new ImageBlock(new URLImage(imageLocation), true);
+        imageBlock.setParameter("alt", title);
+        LinkBlock linkBlock = new LinkBlock(Collections.singletonList((Block) imageBlock), link, true);
+        linkBlock.setParameter("title", title);
+            
+        return Collections.singletonList((Block) linkBlock);
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.xwiki.rendering.macro.Macro#supportsInlineMode()
+     */
+    public boolean supportsInlineMode()
+    {
+        return true;
+    }
+    
+    /**
+     * @param params the chart's parameters
+     * @return the actual chart, build from the given parameters and the given context
+     * @throws Exception in case an error occurs and the chart cannot be build
+     */
+    private File generateChart(Map<String, Object> params) throws Exception
+    {
+        String sourceType = (String) params.get("type");
+        DataSourceFactory factory = getDataSourceFactory(sourceType);
+        DataSource dataSource = factory.create(params);
+        return chartGenerator.buildChart(dataSource, params, tempDir);
+    }
+    
+    /**
+     * @param sourceType the type of source to be initialized
+     * @return a data source which is initialized having its type specified as a string
+     * @throws ComponentLookupException if the source type is invalid
+     */
+    protected DataSourceFactory getDataSourceFactory(String sourceType) throws ComponentLookupException {
+        return (DataSourceFactory) this.componentManager
+            .lookup(DataSourceFactory.class, sourceType);
+    }
+    
+    /**
+     * Initializes a directory for storing temporary content. 
+     * @throws Exception if the directory cannot be opened 
+     */
+    protected void initTempDir() throws Exception
+    {
+        File dir = container.getApplicationContext().getTemporaryDirectory();
+        
+        tempDir = new File(dir, CHARTS_DIR_NAME);
+        tempDir.mkdirs();
+    }
+}
Index: src/main/java/org/xwiki/rendering/macro/chart/ChartMacroParameters.java
===================================================================
--- src/main/java/org/xwiki/rendering/macro/chart/ChartMacroParameters.java	(revision 0)
+++ src/main/java/org/xwiki/rendering/macro/chart/ChartMacroParameters.java	(revision 0)
@@ -0,0 +1,229 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.xwiki.rendering.macro.chart;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.xwiki.chart.ChartGenerator;
+import org.xwiki.rendering.macro.descriptor.annotation.ParameterDescription;
+import org.xwiki.rendering.macro.descriptor.annotation.ParameterMandatory;
+
+/**
+ * Parameters for the {@link org.xwiki.rendering.internal.macro.chart.ChartMacro} Macro.
+ * 
+ * @version $Id: $
+ * @since 1.9
+ */
+public class ChartMacroParameters
+{
+    /**
+     * The name of the 'content' parameter.
+     */
+    public static final String CONTENT = "content";
+
+    /**
+     * The name of the 'content' parameter.
+     */
+    public static final String CONTEXT = "context";
+
+    /**
+     * The name of the 'xdom' parameter.
+     */
+    public static final String XDOM_TREE = "xdom";
+
+    /**
+     * The name of the 'document' parameter.
+     */
+    public static final String DOCUMENT = "document";
+
+    /**
+     * The splitter used to separate the parameters describing the data source.
+     */
+    private static final String PARAMETER_SPLITTER = ";";
+    
+    /**
+     * The type of the chart.
+     */
+    public enum ChartType {
+        /**
+         * Area chart.
+         */
+        AREA,
+        /**
+         * Bar chart.
+         */
+        BAR, 
+        /**
+         * Line chart.
+         */
+        LINE, 
+        /**
+         * Pie chart.
+         */
+        PIE,
+        /**
+         * Time chart.
+         */
+        TIME;
+    };
+    
+    /**
+     * Refer to {@link #getType()}.
+     */
+    private ChartType type;
+
+    /**
+     * Refer to {@link #getSource().
+     */
+    private String source;
+
+    /**
+     * Refer to {@link #getTitle().
+     */
+    private String title;
+    
+    /**
+     * Refer to {@link #getHeight().
+     */
+    private int height = 300;
+    
+    /**
+     * Refer to {@link #getWidth().
+     */
+    private int width = 400;
+    
+    /**
+     * @return The title of the chart.
+     */
+    public String getTitle()
+    {
+        return title;
+    }
+
+    /**
+     * @param title - refer to {@link #getTitle()}.
+     */
+    @ParameterDescription("The title of the chart.")
+    public void setTitle(String title)
+    {
+        this.title = title;
+    }
+
+    /**
+     * @return The width of the chart.
+     */
+    public int getWidth()
+    {
+        return width;
+    }
+
+    /**
+     * @param width - refer to {@link #getWidth()}.
+     */
+    @ParameterDescription("The width of the chart.")
+    public void setWidth(int width)
+    {
+        this.width = width;
+    }
+
+    /**
+     * @return The height of the chart.
+     */
+    public int getHeight()
+    {
+        return height;
+    }
+
+    /**
+     * @param height - refer to {@link #getHeight()}.
+     */
+    @ParameterDescription("The height of the chart.")
+    public void setHeight(int height)
+    {
+        this.height = height;
+    }
+    
+    /**
+     * @return the type of the chart.
+     */
+    public ChartType getType()
+    {
+        return type;
+    }
+
+    /**
+     * @param chartType - refer to {@link #getType()}.
+     */
+    @ParameterMandatory
+    @ParameterDescription("The type of the chart.")
+    public void setType(ChartType chartType)
+    {
+        this.type = chartType;
+    }
+
+    /**
+     * @return a string describing the data source
+     */
+    public String getSource()
+    {
+        return source;
+    }
+
+    /**
+     * @param source - refer to {@link #getSource()
+     */
+    @ParameterDescription("The string describing the data source.")
+    @ParameterMandatory
+    public void setSource(String source)
+    {
+        this.source = source;
+    }
+
+    /**
+     * @return a Map containing all the parameters.
+     */
+    public Map<String, Object> getParametersMap() {
+        Map<String, Object> map = new HashMap<String, Object>();
+        map.put(ChartGenerator.TYPE_PARAM, type.toString());
+        map.put(ChartGenerator.TITLE_PARAM, title);
+        map.put(ChartGenerator.WIDTH_PARAM, width);
+        map.put(ChartGenerator.HEIGHT_PARAM, height);
+        
+        //We're seeking out all the source-specific parameters and we're putting them on the map, too.
+        for (String item : this.source.split(PARAMETER_SPLITTER)) {
+            int index = item.indexOf(":");
+            //In case the parameter doesn't have a value assigned, we ignore him.
+            if (index < 0) {
+                continue;
+            }
+            String key = item.substring(0, index).trim();
+            //In case there is already a macro parameter which has the same name as this 
+            //source descriptor does, we ignore it.
+            if (map.containsKey(key)) {
+                continue;
+            }
+            String value = item.substring(index + 1).trim();
+            map.put(key, value);
+        }
+        
+        return map;
+    }
+}
Index: src/main/resources/META-INF/components.txt
===================================================================
--- src/main/resources/META-INF/components.txt	(revision 0)
+++ src/main/resources/META-INF/components.txt	(revision 0)
@@ -0,0 +1,3 @@
+org.xwiki.rendering.internal.macro.chart.ChartMacro
+org.xwiki.chart.internal.source.InlineDataSourceFactory
+org.xwiki.chart.internal.source.XdomDataSourceFactory
Index: src/test/java/org/xwiki/rendering/internal/MockChartGenerator.java
===================================================================
--- src/test/java/org/xwiki/rendering/internal/MockChartGenerator.java	(revision 0)
+++ src/test/java/org/xwiki/rendering/internal/MockChartGenerator.java	(revision 0)
@@ -0,0 +1,60 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.xwiki.rendering.internal;
+
+import java.io.File;
+import java.util.Map;
+
+import org.xwiki.chart.ChartGenerator;
+import org.xwiki.chart.ChartGeneratorException;
+import org.xwiki.chart.source.DataSource;
+import org.xwiki.component.descriptor.ComponentDescriptor;
+import org.xwiki.component.descriptor.DefaultComponentDescriptor;
+
+/**
+ * Mock {@link ChartGenerator} implementation used for testing.
+ * 
+ * @version $Id: $
+ * @since 1.9
+ */
+public class MockChartGenerator implements ChartGenerator
+{
+    @Override
+    public File buildChart(DataSource dataSource, Map<String, Object> parameters, File outputDirectory)
+        throws ChartGeneratorException
+    {
+        return outputDirectory;
+    }
+
+    /**
+     * Create and return a descriptor for this component.
+     * 
+     * @return the descriptor of the component.
+     */
+    public static ComponentDescriptor getComponentDescriptor()
+    {
+        DefaultComponentDescriptor componentDescriptor = new DefaultComponentDescriptor();
+
+        componentDescriptor.setRole(ChartGenerator.class);
+        componentDescriptor.setImplementation(MockChartGenerator.class.getName());
+
+        return componentDescriptor;
+    }
+}
Index: src/test/java/org/xwiki/rendering/internal/MockDataSourceFactory.java
===================================================================
--- src/test/java/org/xwiki/rendering/internal/MockDataSourceFactory.java	(revision 0)
+++ src/test/java/org/xwiki/rendering/internal/MockDataSourceFactory.java	(revision 0)
@@ -0,0 +1,42 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.xwiki.rendering.internal;
+
+import java.util.Map;
+
+import org.xwiki.chart.ChartGeneratorException;
+import org.xwiki.chart.source.DataSource;
+import org.xwiki.chart.source.DataSourceFactory;
+import org.xwiki.chart.source.DefaultDataSource;
+
+/**
+ * Mock {@link DataSourceFactory} implementation used for testing.
+ * 
+ * @version $Id: $
+ * @since 1.9
+ */public class MockDataSourceFactory implements DataSourceFactory
+{
+
+    @Override
+    public DataSource create(Map<String, Object> params) throws ChartGeneratorException
+    {
+        return new DefaultDataSource();
+    }
+}
Index: src/test/java/org/xwiki/rendering/internal/MockDocumentAccessBridge.java
===================================================================
--- src/test/java/org/xwiki/rendering/internal/MockDocumentAccessBridge.java	(revision 0)
+++ src/test/java/org/xwiki/rendering/internal/MockDocumentAccessBridge.java	(revision 0)
@@ -0,0 +1,224 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.xwiki.rendering.internal;
+
+import java.util.Map;
+
+import org.xwiki.bridge.DocumentAccessBridge;
+import org.xwiki.bridge.DocumentModelBridge;
+import org.xwiki.bridge.DocumentName;
+
+/**
+ * Used for testing the chart macro.
+ * 
+ * @version $Id: $
+ * @since 1.9
+ */
+public class MockDocumentAccessBridge implements DocumentAccessBridge
+{
+    @Override
+    public String getURL(String arg0, String arg1, String arg2, String arg3)
+    {
+        return "http://localhost/image.png";
+    }
+
+    @Override
+    public boolean exists(String arg0)
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    @Override
+    public byte[] getAttachmentContent(String arg0, String arg1) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public String getAttachmentURL(String arg0, String arg1)
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public DocumentName getCurrentDocumentName()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public String getCurrentUser()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public String getDefaultEncoding()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public DocumentModelBridge getDocument(String arg0) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public String getDocumentContent(String arg0) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public String getDocumentContent(String arg0, String arg1) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public String getDocumentContentForDefaultLanguage(String arg0) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public DocumentName getDocumentName(String arg0)
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public String getDocumentSyntaxId(String arg0) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public String getProperty(String arg0, String arg1) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public String getProperty(String arg0, String arg1, String arg2) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public String getProperty(String arg0, String arg1, int arg2, String arg3) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public String getPropertyType(String arg0, String arg1) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public boolean hasProgrammingRights()
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    @Override
+    public boolean isDocumentEditable(String arg0)
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    @Override
+    public boolean isDocumentViewable(String arg0)
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    @Override
+    public boolean isPropertyCustomMapped(String arg0, String arg1) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    @Override
+    public void popDocumentFromContext(Map<String, Object> arg0)
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public void pushDocumentInContext(Map<String, Object> arg0, String arg1) throws Exception
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public void setAttachmentContent(String arg0, String arg1, byte[] arg2) throws Exception
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public void setDocumentContent(String arg0, String arg1, String arg2, boolean arg3) throws Exception
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public void setDocumentSyntaxId(String arg0, String arg1) throws Exception
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public void setProperty(String arg0, String arg1, String arg2, Object arg3) throws Exception
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+}
Index: src/test/java/org/xwiki/rendering/macro/chart/TestChartMacro.java
===================================================================
--- src/test/java/org/xwiki/rendering/macro/chart/TestChartMacro.java	(revision 0)
+++ src/test/java/org/xwiki/rendering/macro/chart/TestChartMacro.java	(revision 0)
@@ -0,0 +1,74 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.xwiki.rendering.macro.chart;
+
+import java.io.File;
+import org.xwiki.component.manager.ComponentLookupException;
+import org.xwiki.chart.internal.source.InlineDataSourceFactory;
+import org.xwiki.chart.source.DataSourceFactory;
+import org.xwiki.rendering.internal.MockChartGenerator;
+import org.xwiki.rendering.internal.MockDocumentAccessBridge;
+import org.xwiki.rendering.internal.macro.chart.ChartMacro;
+
+/**
+ * Inherits the ChartMacro and mocks all the dependencies. Used for testing purposes.
+ * 
+ * @version $Id: $
+ * @since 1.9
+ */
+
+public class TestChartMacro extends ChartMacro
+{
+    private DataSourceFactory dataSourceFactory;
+ 
+    public void setDataSourceFactory(DataSourceFactory dataSourceFactory)
+    {
+        this.dataSourceFactory = dataSourceFactory;
+    }
+
+    /**
+     * Initializes a directory for storing temporary content. 
+     * @throws Exception if the directory cannot be opened 
+     */
+    @Override
+    protected void initTempDir() throws Exception
+    {
+        String tempDirLocation = System.getProperty("java.io.tmpdir"); 
+        this.tempDir = new File(tempDirLocation, "chartGenerator");
+        this.tempDir.mkdirs();
+    }
+ 
+    @Override
+    protected DataSourceFactory getDataSourceFactory(String sourceType) throws ComponentLookupException {
+        return this.dataSourceFactory != null
+            ? this.dataSourceFactory
+            : new InlineDataSourceFactory();
+    }
+    
+    /**
+     * Default constructor. It mocks every dependency, so that the macro can be executed in a test environment. 
+     */
+    public TestChartMacro() 
+    {
+        super();
+        this.chartGenerator = new MockChartGenerator();
+        this.documentAccessBridge = new MockDocumentAccessBridge();
+    }
+}
Index: src/test/java/org/xwiki/rendering/ChartMacroTests.java
===================================================================
--- src/test/java/org/xwiki/rendering/ChartMacroTests.java	(revision 0)
+++ src/test/java/org/xwiki/rendering/ChartMacroTests.java	(revision 0)
@@ -0,0 +1,83 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.xwiki.rendering;
+
+import java.util.List;
+import org.xwiki.chart.ChartGeneratorException;
+import org.xwiki.chart.source.DataSourceFactory;
+import org.xwiki.rendering.block.Block;
+import org.xwiki.rendering.block.ImageBlock;
+import org.xwiki.rendering.block.LinkBlock;
+import org.xwiki.rendering.internal.MockDataSourceFactory;
+import org.xwiki.rendering.listener.URLImage;
+import org.xwiki.rendering.macro.chart.ChartMacroParameters;
+import org.xwiki.rendering.macro.chart.TestChartMacro;
+import org.xwiki.rendering.macro.chart.ChartMacroParameters.ChartType;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for {@link ChartMacro}.
+ * 
+ * @version $Id: $
+ * @since 1.9
+ */
+public class ChartMacroTests extends TestCase
+{
+    private TestChartMacro testMacro;
+    private static final int HEIGHT = 122;
+    private static final int WIDTH = 122;
+    private static final String TITLE = "Testing the chart macro.";
+    
+    public ChartMacroTests(String name)
+    {
+        super(name);
+        this.testMacro = new TestChartMacro();
+    }
+
+    /**
+     * Tests whether the component is able to build a pie chart.
+     * @throws ChartGeneratorException in case the chart cannot be build.
+     */
+    public final void testChartMacro() throws Exception
+    {
+        DataSourceFactory dataSourceFactory = new MockDataSourceFactory();
+        ChartMacroParameters parameters = new ChartMacroParameters();
+        parameters.setHeight(HEIGHT);
+        parameters.setWidth(WIDTH);
+        parameters.setTitle(TITLE);
+        parameters.setType(ChartType.PIE);
+        parameters.setSource("type:inline");
+        String content="|AAA | BBB ($)\n|Category 1 | 20\n|Category 2 | 500\n|Category 3 | 300";
+        
+        this.testMacro.setDataSourceFactory(dataSourceFactory);
+        List<Block> result = this.testMacro.execute(parameters, content, null);
+        assert result.size() == 1;
+        assert result.get(0) instanceof LinkBlock;
+        LinkBlock linkBlock = (LinkBlock) result.get(0);
+        assertEquals(linkBlock.getParameter("title"), TITLE);
+        assertEquals(linkBlock.getLink().getReference(), "http://localhost/image.png/chartGenerator");
+        assert linkBlock.getChildren().size() == 1;
+        assert linkBlock.getChildren().get(0) instanceof ImageBlock;
+        ImageBlock imageBlock = (ImageBlock) linkBlock.getChildren().get(0);
+        assertEquals(((URLImage) imageBlock.getImage()).getURL(), "http://localhost/image.png/chartGenerator");
+    }
+}
Index: pom.xml
===================================================================
--- pom.xml	(revision 0)
+++ pom.xml	(revision 0)
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ *
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <artifactId>xwiki-core-rendering-macros-parent</artifactId>
+    <groupId>org.xwiki.platform</groupId>
+    <version>1.9-SNAPSHOT</version>
+  </parent>
+  <artifactId>xwiki-core-rendering-macro-chart</artifactId>
+  <name>XWiki Platform - Core - Rendering - Macro - Chart</name>
+  <version>1.9-SNAPSHOT</version>
+  <description>XWiki Platform - Core - Rendering - Macro - Chart</description>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <includes>
+            <include>**/ChartMacroTests.java</include>
+          </includes>
+        </configuration>
+      </plugin>
+      <!-- Apply the Checkstyle configurations defined in the top level pom.xml file -->
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-checkstyle-plugin</artifactId>
+      </plugin>
+    </plugins>
+  </build>
+  <dependencies>
+    <dependency>
+	  <groupId>org.xwiki.platform</groupId>
+  	  <artifactId>xwiki-core-jfreechart</artifactId>
+      <version>${pom.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.xwiki.platform</groupId>
+      <artifactId>xwiki-core-container-api</artifactId>
+      <version>${pom.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.xwiki.platform</groupId>
+      <artifactId>xwiki-core-bridge</artifactId>
+      <version>${pom.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.xwiki.platform</groupId>
+      <artifactId>xwiki-core-rendering-macro-include</artifactId>
+      <version>${pom.version}</version>
+    </dependency>
+  </dependencies>
+</project>

