Search in sources :

Example 1 with LineChartProperties

use of org.jCharts.properties.LineChartProperties in project jmeter by apache.

the class RespTimeGraphChart method drawSample.

private void drawSample(String _title, String[] _xAxisLabels, String _yAxisTitle, String[] _legendLabels, double[][] _data, int _width, int _height, int _incrScaleYAxis, Color[] _color, Font legendFont, Graphics g) {
    // define max scale y axis
    double max = maxYAxisScale > 0 ? maxYAxisScale : getTopValue(findMax(_data), BigDecimal.ROUND_UP);
    try {
        // if the title graph is empty, we can assume some default
        if (_title.length() == 0) {
            //$NON-NLS-1$
            _title = JMeterUtils.getResString("graph_resp_time_title");
        }
        this.setPreferredSize(new Dimension(_width, _height));
        // replace _xAxisTitle to null (don't display x axis title)
        DataSeries dataSeries = new DataSeries(_xAxisLabels, null, _yAxisTitle, _title);
        // Stroke and shape line settings
        Stroke[] strokes = new Stroke[_legendLabels.length];
        for (int i = 0; i < _legendLabels.length; i++) {
            strokes[i] = new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 5f);
        }
        Shape[] shapes = new Shape[_legendLabels.length];
        for (int i = 0; i < _legendLabels.length; i++) {
            shapes[i] = pointShape;
        }
        LineChartProperties lineChartProperties = new LineChartProperties(strokes, shapes);
        // Lines colors
        Paint[] paints = new Paint[_color.length];
        System.arraycopy(_color, 0, paints, 0, _color.length);
        // Define chart type (line)
        AxisChartDataSet axisChartDataSet = new AxisChartDataSet(_data, _legendLabels, paints, ChartType.LINE, lineChartProperties);
        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 ruler
        try {
            // ~a tic every 50 px
            double numInterval = _height / 50d;
            double incrYAxis = max / numInterval;
            double incrTopValue = _incrScaleYAxis;
            if (_incrScaleYAxis == 0) {
                incrTopValue = getTopValue(incrYAxis, BigDecimal.ROUND_HALF_UP);
            }
            if (incrTopValue < 1) {
                // Increment cannot be < 1
                incrTopValue = 1.0d;
            }
            yaxis.setUserDefinedScale(0, incrTopValue);
            yaxis.setNumItems((int) (max / incrTopValue) + 1);
            yaxis.setShowGridLines(1);
        } catch (PropertyException e) {
            log.warn("Exception while setting Y axis properties.", e);
        }
        AxisProperties axisProperties = new AxisProperties(xaxis, yaxis);
        axisProperties.setXAxisLabelsAreVertical(true);
        LegendProperties legendProperties = new LegendProperties();
        legendProperties.setBorderStroke(null);
        legendProperties.setPlacement(legendPlacement);
        legendProperties.setIconBorderPaint(Color.WHITE);
        legendProperties.setIconBorderStroke(new BasicStroke(0f, BasicStroke.CAP_SQUARE, BasicStroke.CAP_SQUARE));
        // Manage legend placement
        legendProperties.setNumColumns(LegendAreaProperties.COLUMNS_FIT_TO_IMAGE);
        if (legendPlacement == LegendAreaProperties.RIGHT || legendPlacement == LegendAreaProperties.LEFT) {
            legendProperties.setNumColumns(1);
        }
        if (legendFont != null) {
            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 while rendering axis chart.", e);
    }
}
Also used : BasicStroke(java.awt.BasicStroke) LineChartProperties(org.jCharts.properties.LineChartProperties) ChartFont(org.jCharts.properties.util.ChartFont) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Shape(java.awt.Shape) 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) DataAxisProperties(org.jCharts.properties.DataAxisProperties) LegendProperties(org.jCharts.properties.LegendProperties) ChartProperties(org.jCharts.properties.ChartProperties) PointChartProperties(org.jCharts.properties.PointChartProperties) LineChartProperties(org.jCharts.properties.LineChartProperties) ChartDataException(org.jCharts.chartData.ChartDataException) DataSeries(org.jCharts.chartData.DataSeries) LabelAxisProperties(org.jCharts.properties.LabelAxisProperties)

Example 2 with LineChartProperties

use of org.jCharts.properties.LineChartProperties in project jmeter by apache.

the class LineGraph method drawSample.

private void drawSample(String _title, String[] _xAxisLabels, String _xAxisTitle, String _yAxisTitle, double[][] _data, int _width, int _height, Graphics g) {
    try {
        if (_width == 0) {
            _width = 450;
        }
        if (_height == 0) {
            _height = 250;
        }
        this.setPreferredSize(new Dimension(_width, _height));
        DataSeries dataSeries = new DataSeries(_xAxisLabels, _xAxisTitle, _yAxisTitle, _title);
        String[] legendLabels = yAxisLabel;
        Paint[] paints = this.createPaint(_data.length);
        Shape[] shapes = createShapes(_data.length);
        Stroke[] lstrokes = createStrokes(_data.length);
        LineChartProperties lineChartProperties = new LineChartProperties(lstrokes, shapes);
        AxisChartDataSet axisChartDataSet = new AxisChartDataSet(_data, legendLabels, paints, ChartType.LINE, lineChartProperties);
        dataSeries.addIAxisPlotDataSet(axisChartDataSet);
        ChartProperties chartProperties = new ChartProperties();
        AxisProperties axisProperties = new AxisProperties();
        // show the grid lines, to turn it off, set it to zero
        axisProperties.getYAxisProperties().setShowGridLines(1);
        axisProperties.setXAxisLabelsAreVertical(true);
        // set the Y Axis to round
        DataAxisProperties daxp = (DataAxisProperties) axisProperties.getYAxisProperties();
        daxp.setRoundToNearest(1);
        LegendProperties legendProperties = new LegendProperties();
        AxisChart axisChart = new AxisChart(dataSeries, chartProperties, axisProperties, legendProperties, _width, _height);
        axisChart.setGraphics2D((Graphics2D) g);
        axisChart.render();
    } catch (Exception e) {
        log.error("Error while rendering axis chart. {}", e.getMessage());
    }
}
Also used : LineChartProperties(org.jCharts.properties.LineChartProperties) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Shape(java.awt.Shape) AxisChart(org.jCharts.axisChart.AxisChart) AxisProperties(org.jCharts.properties.AxisProperties) DataAxisProperties(org.jCharts.properties.DataAxisProperties) AxisChartDataSet(org.jCharts.chartData.AxisChartDataSet) Dimension(java.awt.Dimension) Paint(java.awt.Paint) DataAxisProperties(org.jCharts.properties.DataAxisProperties) LegendProperties(org.jCharts.properties.LegendProperties) PointChartProperties(org.jCharts.properties.PointChartProperties) LineChartProperties(org.jCharts.properties.LineChartProperties) ChartProperties(org.jCharts.properties.ChartProperties) DataSeries(org.jCharts.chartData.DataSeries)

Aggregations

BasicStroke (java.awt.BasicStroke)2 Dimension (java.awt.Dimension)2 Paint (java.awt.Paint)2 Shape (java.awt.Shape)2 Stroke (java.awt.Stroke)2 AxisChart (org.jCharts.axisChart.AxisChart)2 AxisChartDataSet (org.jCharts.chartData.AxisChartDataSet)2 DataSeries (org.jCharts.chartData.DataSeries)2 AxisProperties (org.jCharts.properties.AxisProperties)2 ChartProperties (org.jCharts.properties.ChartProperties)2 DataAxisProperties (org.jCharts.properties.DataAxisProperties)2 LegendProperties (org.jCharts.properties.LegendProperties)2 LineChartProperties (org.jCharts.properties.LineChartProperties)2 PointChartProperties (org.jCharts.properties.PointChartProperties)2 Color (java.awt.Color)1 ChartDataException (org.jCharts.chartData.ChartDataException)1 LabelAxisProperties (org.jCharts.properties.LabelAxisProperties)1 PropertyException (org.jCharts.properties.PropertyException)1 ChartFont (org.jCharts.properties.util.ChartFont)1