Search in sources :

Example 1 with ValueLabelRenderer

use of org.jCharts.axisChart.customRenderers.axisValue.renderers.ValueLabelRenderer in project jmeter by apache.

the class AxisGraph method drawSample.

private void drawSample(String _title, int _maxLength, String[] _xAxisLabels, String _yAxisTitle, String[] _legendLabels, double[][] _data, int _width, int _height, Color[] _color, Font legendFont, Graphics g) {
    // define max scale y axis
    double max = maxYAxisScale > 0 ? maxYAxisScale : findMax(_data);
    try {
        /** These controls are already done in StatGraphVisualizer
            if (_width == 0) {
                _width = 450;
            }
            if (_height == 0) {
                _height = 250;
            }
            **/
        if (_maxLength < 3) {
            _maxLength = 3;
        }
        // if the "Title of Graph" is empty, we can assume some default
        if (_title.length() == 0) {
            //$NON-NLS-1$
            _title = JMeterUtils.getResString("aggregate_graph_title");
        }
        // if the labels are too long, they'll be "squeezed" to make the chart viewable.
        for (int i = 0; i < _xAxisLabels.length; i++) {
            String label = _xAxisLabels[i];
            _xAxisLabels[i] = squeeze(label, _maxLength);
        }
        this.setPreferredSize(new Dimension(_width, _height));
        // replace _xAxisTitle to null (don't display x axis title)
        DataSeries dataSeries = new DataSeries(_xAxisLabels, null, _yAxisTitle, _title);
        ClusteredBarChartProperties clusteredBarChartProperties = new ClusteredBarChartProperties();
        clusteredBarChartProperties.setShowOutlinesFlag(outlinesBarFlag);
        ValueLabelRenderer valueLabelRenderer = new ValueLabelRenderer(false, false, showGrouping, 0);
        valueLabelRenderer.setValueLabelPosition(ValueLabelPosition.AT_TOP);
        valueLabelRenderer.setValueChartFont(new ChartFont(valueFont, foreColor));
        valueLabelRenderer.useVerticalLabels(valueOrientation);
        clusteredBarChartProperties.addPostRenderEventListener(valueLabelRenderer);
        Paint[] paints = new Paint[_color.length];
        System.arraycopy(_color, 0, paints, 0, paints.length);
        AxisChartDataSet axisChartDataSet = new AxisChartDataSet(_data, _legendLabels, paints, ChartType.BAR_CLUSTERED, clusteredBarChartProperties);
        dataSeries.addIAxisPlotDataSet(axisChartDataSet);
        ChartProperties chartProperties = new ChartProperties();
        LabelAxisProperties xaxis = new LabelAxisProperties();
        DataAxisProperties yaxis = new DataAxisProperties();
        yaxis.setUseCommas(showGrouping);
        if (legendFont != null) {
            yaxis.setAxisTitleChartFont(new ChartFont(legendFont, new Color(20)));
            yaxis.setScaleChartFont(new ChartFont(legendFont, new Color(20)));
            xaxis.setAxisTitleChartFont(new ChartFont(legendFont, new Color(20)));
            xaxis.setScaleChartFont(new ChartFont(legendFont, new Color(20)));
        }
        if (titleFont != null) {
            chartProperties.setTitleFont(new ChartFont(titleFont, new Color(0)));
        }
        // Y Axis
        try {
            BigDecimal round = BigDecimal.valueOf(max / 1000d);
            round = round.setScale(0, BigDecimal.ROUND_UP);
            double topValue = round.doubleValue() * 1000;
            yaxis.setUserDefinedScale(0, 500);
            yaxis.setNumItems((int) (topValue / 500) + 1);
            yaxis.setShowGridLines(1);
        } catch (PropertyException e) {
            log.warn("Chart property exception occurred.", e);
        }
        AxisProperties axisProperties = new AxisProperties(xaxis, yaxis);
        axisProperties.setXAxisLabelsAreVertical(true);
        LegendProperties legendProperties = new LegendProperties();
        legendProperties.setBorderStroke(null);
        legendProperties.setPlacement(legendPlacement);
        legendProperties.setIconBorderPaint(Color.WHITE);
        if (legendPlacement == LegendAreaProperties.RIGHT || legendPlacement == LegendAreaProperties.LEFT) {
            legendProperties.setNumColumns(1);
        }
        if (legendFont != null) {
            //new Font("SansSerif", Font.PLAIN, 10)
            legendProperties.setFont(legendFont);
        }
        AxisChart axisChart = new AxisChart(dataSeries, chartProperties, axisProperties, legendProperties, _width, _height);
        axisChart.setGraphics2D((Graphics2D) g);
        axisChart.render();
    } catch (ChartDataException | PropertyException e) {
        log.warn("Exception occurred while rendering chart.", e);
    }
}
Also used : ValueLabelRenderer(org.jCharts.axisChart.customRenderers.axisValue.renderers.ValueLabelRenderer) ChartFont(org.jCharts.properties.util.ChartFont) AxisChart(org.jCharts.axisChart.AxisChart) PropertyException(org.jCharts.properties.PropertyException) Color(java.awt.Color) AxisProperties(org.jCharts.properties.AxisProperties) DataAxisProperties(org.jCharts.properties.DataAxisProperties) LabelAxisProperties(org.jCharts.properties.LabelAxisProperties) AxisChartDataSet(org.jCharts.chartData.AxisChartDataSet) Dimension(java.awt.Dimension) Paint(java.awt.Paint) Paint(java.awt.Paint) BigDecimal(java.math.BigDecimal) DataAxisProperties(org.jCharts.properties.DataAxisProperties) ClusteredBarChartProperties(org.jCharts.properties.ClusteredBarChartProperties) LegendProperties(org.jCharts.properties.LegendProperties) ChartProperties(org.jCharts.properties.ChartProperties) ClusteredBarChartProperties(org.jCharts.properties.ClusteredBarChartProperties) ChartDataException(org.jCharts.chartData.ChartDataException) DataSeries(org.jCharts.chartData.DataSeries) LabelAxisProperties(org.jCharts.properties.LabelAxisProperties)

Aggregations

Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 Paint (java.awt.Paint)1 BigDecimal (java.math.BigDecimal)1 AxisChart (org.jCharts.axisChart.AxisChart)1 ValueLabelRenderer (org.jCharts.axisChart.customRenderers.axisValue.renderers.ValueLabelRenderer)1 AxisChartDataSet (org.jCharts.chartData.AxisChartDataSet)1 ChartDataException (org.jCharts.chartData.ChartDataException)1 DataSeries (org.jCharts.chartData.DataSeries)1 AxisProperties (org.jCharts.properties.AxisProperties)1 ChartProperties (org.jCharts.properties.ChartProperties)1 ClusteredBarChartProperties (org.jCharts.properties.ClusteredBarChartProperties)1 DataAxisProperties (org.jCharts.properties.DataAxisProperties)1 LabelAxisProperties (org.jCharts.properties.LabelAxisProperties)1 LegendProperties (org.jCharts.properties.LegendProperties)1 PropertyException (org.jCharts.properties.PropertyException)1 ChartFont (org.jCharts.properties.util.ChartFont)1