Search in sources :

Example 1 with AxisType

use of org.xwiki.chart.axis.AxisType in project xwiki-platform by xwiki.

the class AxisConfigurator method setAxes.

/**
 * Set the axes in the chart model.
 *
 * @param plotType The target plot type.
 * @param chartModel The target chart model.
 * @throws MacroExecutionException if the axes are incorrectly configured.
 */
public void setAxes(PlotType plotType, SimpleChartModel chartModel) throws MacroExecutionException {
    AxisType[] defaultAxisTypes = plotType.getDefaultAxisTypes();
    for (int i = 0; i < axisTypes.length; i++) {
        AxisType type = axisTypes[i];
        if (i >= defaultAxisTypes.length) {
            if (type != null) {
                throw new MacroExecutionException("To many axes for plot type.");
            }
            continue;
        }
        if (type == null) {
            type = defaultAxisTypes[i];
        }
        Axis axis;
        switch(type) {
            case NUMBER:
                NumberAxis numberAxis = new NumberAxis();
                axis = numberAxis;
                setNumberLimits(numberAxis, i);
                break;
            case CATEGORY:
                axis = new CategoryAxis();
                break;
            case DATE:
                DateAxis dateAxis = new DateAxis();
                axis = dateAxis;
                dateAxis.setTickMarkPosition(DateTickMarkPosition.END);
                if (axisDateFormat[i] != null) {
                    try {
                        DateFormat dateFormat = new SimpleDateFormat(axisDateFormat[i], localeConfiguration.getLocale());
                        dateAxis.setDateFormatOverride(dateFormat);
                    } catch (IllegalArgumentException e) {
                        throw new MacroExecutionException(String.format("Invalid date format [%s].", axisDateFormat[i]));
                    }
                }
                setDateLimits(dateAxis, i);
                break;
            default:
                throw new MacroExecutionException(String.format("Unsupported axis type [%s]", type.getName()));
        }
        chartModel.setAxis(i, axis);
    }
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) CategoryAxis(org.jfree.chart.axis.CategoryAxis) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) MacroExecutionException(org.xwiki.rendering.macro.MacroExecutionException) AxisType(org.xwiki.chart.axis.AxisType) SimpleDateFormat(java.text.SimpleDateFormat) ValueAxis(org.jfree.chart.axis.ValueAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) DateAxis(org.jfree.chart.axis.DateAxis) Axis(org.jfree.chart.axis.Axis) CategoryAxis(org.jfree.chart.axis.CategoryAxis)

Example 2 with AxisType

use of org.xwiki.chart.axis.AxisType in project xwiki-platform by xwiki.

the class AxisConfigurator method setParameter.

@Override
public boolean setParameter(String key, String value) throws MacroExecutionException {
    boolean claimed = true;
    if (DOMAIN_AXIS_PARAM.equals(key)) {
        AxisType type = AxisType.forName(value);
        if (type == null) {
            invalidParameterValue(DOMAIN_AXIS_PARAM, value);
        }
        setAxisType(0, type);
    } else if (DOMAIN_AXIS_DATE_FORMAT_PARAM.equals(key)) {
        setAxisDateFormat(0, value);
    } else if (RANGE_AXIS_PARAM.equals(key)) {
        AxisType type = AxisType.forName(value);
        if (type == null) {
            invalidParameterValue(RANGE_AXIS_PARAM, value);
        }
        setAxisType(1, type);
    } else if (RANGE_AXIS_DATE_FORMAT_PARAM.equals(key)) {
        setAxisDateFormat(0, value);
    } else if (!claimLimitParameters(key, value)) {
        claimed = false;
    }
    return claimed;
}
Also used : AxisType(org.xwiki.chart.axis.AxisType)

Aggregations

AxisType (org.xwiki.chart.axis.AxisType)2 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Axis (org.jfree.chart.axis.Axis)1 CategoryAxis (org.jfree.chart.axis.CategoryAxis)1 DateAxis (org.jfree.chart.axis.DateAxis)1 NumberAxis (org.jfree.chart.axis.NumberAxis)1 ValueAxis (org.jfree.chart.axis.ValueAxis)1 MacroExecutionException (org.xwiki.rendering.macro.MacroExecutionException)1