Search in sources :

Example 26 with BaseChart

use of org.eclipse.swtchart.extensions.core.BaseChart in project swtchart by eclipse.

the class SeriesLabelMarker method paintControl.

@Override
public void paintControl(PaintEvent e) {
    if (isDraw()) {
        BaseChart baseChart = getBaseChart();
        ISeriesSet seriesSet = baseChart.getSeriesSet();
        ISeries[] series = seriesSet.getSeries();
        for (ISeries serie : series) {
            String label = serie.getId();
            ISeriesSettings seriesSettings = baseChart.getSeriesSettings(label);
            if (seriesSettings.isVisible()) {
                /*
					 * Only draw is series is visible.
					 */
                int symbolSize = 1;
                if (seriesSettings instanceof IPointSeriesSettings) {
                    symbolSize = ((IPointSeriesSettings) seriesSettings).getSymbolSize();
                }
                /*
					 * Draw the label
					 */
                e.gc.setForeground(getForegroundColor());
                for (int i = 0; i < serie.getXSeries().length; i++) {
                    Point point = serie.getPixelCoordinates(i);
                    Point labelSize = e.gc.textExtent(label);
                    e.gc.drawText(label, (int) (point.x - labelSize.x / 2.0d), (int) (point.y - labelSize.y - symbolSize / 2.0d), true);
                }
            }
        }
    }
}
Also used : BaseChart(org.eclipse.swtchart.extensions.core.BaseChart) ISeriesSet(org.eclipse.swtchart.ISeriesSet) IPointSeriesSettings(org.eclipse.swtchart.extensions.core.IPointSeriesSettings) ISeriesSettings(org.eclipse.swtchart.extensions.core.ISeriesSettings) Point(org.eclipse.swt.graphics.Point) ISeries(org.eclipse.swtchart.ISeries) Point(org.eclipse.swt.graphics.Point)

Example 27 with BaseChart

use of org.eclipse.swtchart.extensions.core.BaseChart in project swtchart by eclipse.

the class AxisZeroMarker method paintControl.

@Override
public void paintControl(PaintEvent e) {
    if (isDraw()) {
        BaseChart baseChart = getBaseChart();
        Range xRange = baseChart.getAxisSet().getXAxes()[BaseChart.ID_PRIMARY_X_AXIS].getRange();
        Range yRange = baseChart.getAxisSet().getYAxes()[BaseChart.ID_PRIMARY_Y_AXIS].getRange();
        /*
			 * Mark the zero lines if possible.
			 * Otherwise draw the marker in half width.
			 */
        if (xRange.lower < 0 && xRange.upper > 0 && yRange.lower < 0 && yRange.upper > 0) {
            Rectangle rectangle = baseChart.getPlotArea().getClientArea();
            int width = rectangle.width;
            int height = rectangle.height;
            int xWidth;
            int yHeight;
            /*
				 * Dependent where the zero values are.
				 * xDelta and yDelta can't be zero -> protect from division by zero.
				 */
            double xDelta = xRange.upper - xRange.lower;
            double yDelta = yRange.upper - yRange.lower;
            // lower is negative
            double xDiff = xRange.lower * -1;
            double yDiff = yRange.upper;
            // percent -> 0.0 - 1.0
            double xPart = ((100 / xDelta) * xDiff) / 100;
            // percent -> 0.0 - 1.0
            double yPart = ((100 / yDelta) * yDiff) / 100;
            xWidth = (int) (width * xPart);
            yHeight = (int) (height * yPart);
            /*
				 * Draw the line.
				 */
            e.gc.setForeground(getForegroundColor());
            // Vertical line through zero
            e.gc.drawLine(xWidth, 0, xWidth, height);
            // Horizontal line through zero
            e.gc.drawLine(0, yHeight, width, yHeight);
        }
    }
}
Also used : BaseChart(org.eclipse.swtchart.extensions.core.BaseChart) Rectangle(org.eclipse.swt.graphics.Rectangle) Range(org.eclipse.swtchart.Range)

Example 28 with BaseChart

use of org.eclipse.swtchart.extensions.core.BaseChart in project swtchart by eclipse.

the class LegendMarker method paintControl.

@Override
public void paintControl(PaintEvent e) {
    if (isDraw()) {
        stringBuilder.delete(0, stringBuilder.length());
        e.gc.setForeground(getForegroundColor());
        // 
        BaseChart baseChart = getBaseChart();
        double primaryValueX = baseChart.getSelectedPrimaryAxisValue(getX(), IExtendedChart.X_AXIS);
        double primaryValueY = baseChart.getSelectedPrimaryAxisValue(getY(), IExtendedChart.Y_AXIS);
        // 
        drawXAxes(primaryValueX);
        drawYAxes(primaryValueY);
        e.gc.drawText(stringBuilder.toString(), 10, 10);
    }
}
Also used : BaseChart(org.eclipse.swtchart.extensions.core.BaseChart)

Aggregations

BaseChart (org.eclipse.swtchart.extensions.core.BaseChart)28 Point (org.eclipse.swt.graphics.Point)8 ISeries (org.eclipse.swtchart.ISeries)8 IAxisSettings (org.eclipse.swtchart.extensions.core.IAxisSettings)8 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)6 IAxisScaleConverter (org.eclipse.swtchart.extensions.core.IAxisScaleConverter)6 Button (org.eclipse.swt.widgets.Button)5 File (java.io.File)4 ISeriesData (org.eclipse.swtchart.extensions.core.ISeriesData)4 FileNotFoundException (java.io.FileNotFoundException)3 PrintWriter (java.io.PrintWriter)3 FileDialog (org.eclipse.swt.widgets.FileDialog)3 ISecondaryAxisSettings (org.eclipse.swtchart.extensions.core.ISecondaryAxisSettings)3 SeriesException (org.eclipse.swtchart.extensions.exceptions.SeriesException)3 DecimalFormat (java.text.DecimalFormat)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 ILineSeries (org.eclipse.swtchart.ILineSeries)2