Author |
Topic |
|
png
USA
6 Posts |
Posted - 10 Oct 2014 : 18:43:26
|
When I tried to use the DataCursor object to draw a vertical line on a chart, I received an error related to the DataCursor.mousePressed.
The code I used to create the DataCursor object is as follows:
DataCursor dataCursorObj = new DataCursor( chartView, pTransform, ChartConstants.MARKER_VLINE, 8.0); dataCursorObj.setDataCursorEnable(true); dataCursorObj.addDataCursorListener(); dataCursorObj.setLineColor(Color.BLACK);
And the error I received is as follows:
Exception in thread "AWT-EventQueue-0" java.lang.InternalError: not implemented yet ... com.quinncurtis.chart2djava.DataCursor.mousePressed(DataCursor.java:229)
Please advice if I'm missing something or if there's a known bug with using the DataCursor object. Thanks.
|
|
quinncurtis
1586 Posts |
Posted - 11 Oct 2014 : 09:10:15
|
I replaced the DataCursor setup code in our datacursorsandmarkers.DataCursorChart example program, with yours, and could not reproduce an error.
DataCursor dataCursorObj = new DataCursor( gWG, pTransform1,
ChartConstants.MARKER_VLINE, 8.0);
dataCursorObj.setDataCursorEnable(true);
dataCursorObj.addDataCursorListener();
dataCursorObj.setLineColor(Color.BLACK);
Try and do the same and let us know if you can reproduce the error. |
|
|
png
USA
6 Posts |
Posted - 14 Oct 2014 : 14:14:46
|
Hello, thanks for the reply. I tried substituting the code but am still getting the datacursor error.
FYI, my development environment is as follows:
Windows 7 Enterprise Edition NetBeans IDE 8.0 Java 8.0.xx
And, here's my simple test code:
QCChart2D_DataCursorViewer.java (contains Main):
public class QCChart2D_DataCursorViewer extends javax.swing.JFrame { /** * Creates new form QCChart2D_DataCursorViewer */ public QCChart2D_DataCursorViewer() { initComponents();
this.setSize(new Dimension(800, 600)); this.setLocationRelativeTo(null); DataCursorChart1 chart = new DataCursorChart1(); this.panelViewer.add(chart, BorderLayout.CENTER); }
public static void main(String args[]) {
/* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new QCChart2D_DataCursorViewer().setVisible(true); } }); }
// Variables declaration - do not modify private javax.swing.JPanel panelViewer; // End of variables declaration }
DataCursorChart1.java:
public class DataCursorChart1 extends ChartView { static final long serialVersionUID = -7989776252346382234L; ChartView gWG = this; SimpleLinePlot thePlot1; SimpleLinePlot thePlot2; LinearAxis xAxis; LinearAxis yAxis; Font theFont;
public DataCursorChart1() { int i; int numPoints = 500; double x1[] = new double[numPoints]; double y1[] = new double[numPoints]; double y2[] = new double[numPoints]; double startP1 = 100; double startP2 = 50;
for (i=0; i < numPoints; i++) { x1[i] = (double)(i) * 0.01; startP1 = startP1 + (0.5 - Math.random()) * 10; y1[i] = startP1; startP2 = startP2 + (0.5 - Math.random()) * 6; y2[i] = startP2; }
theFont = new Font("SansSerif", Font.BOLD,12); SimpleDataset Dataset1 = new SimpleDataset("First",x1,y1); SimpleDataset Dataset2 = new SimpleDataset("Second",x1,y2);
SimpleDataset datasetarray[] = {Dataset1, Dataset2};
CartesianCoordinates pTransform1 = new CartesianCoordinates( ChartConstants.LINEAR_SCALE, ChartConstants.LINEAR_SCALE); pTransform1.autoScale(datasetarray,ChartConstants.AUTOAXES_FAR, ChartConstants.AUTOAXES_FAR);
pTransform1.setGraphBorderDiagonal(0.15, .15, .85, 0.75) ; Background background = new Background( pTransform1, ChartConstants.GRAPH_BACKGROUND, Color.white); gWG.addChartObject(background);
LinearAxis xAxis = new LinearAxis(pTransform1, ChartConstants.X_AXIS); gWG.addChartObject(xAxis);
LinearAxis yAxis = new LinearAxis(pTransform1, ChartConstants.Y_AXIS); gWG.addChartObject(yAxis);
NumericAxisLabels xAxisLab = new NumericAxisLabels(xAxis); xAxisLab.setTextFont(theFont); gWG.addChartObject(xAxisLab);
NumericAxisLabels yAxisLab = new NumericAxisLabels(yAxis); yAxisLab.setTextFont(theFont); gWG.addChartObject(yAxisLab);
Grid xgrid = new Grid(xAxis, yAxis,ChartConstants.X_AXIS, ChartConstants.GRID_MAJOR); gWG.addChartObject(xgrid);
Grid ygrid = new Grid(xAxis, yAxis,ChartConstants.Y_AXIS, ChartConstants.GRID_MAJOR); gWG.addChartObject(ygrid);
ChartAttribute attrib1 = new ChartAttribute (Color.blue, 1,ChartConstants.LS_SOLID); thePlot1 = new SimpleLinePlot(pTransform1, Dataset1, attrib1); gWG.addChartObject(thePlot1);
ChartAttribute attrib2 = new ChartAttribute (Color.red, 1,ChartConstants.LS_SOLID); thePlot2 = new SimpleLinePlot(pTransform1, Dataset2, attrib2); gWG.addChartObject(thePlot2); DataCursor dataCursorObj = new DataCursor(gWG, pTransform1,ChartConstants.MARKER_VLINE,8.0); dataCursorObj.setDataCursorEnable(true); dataCursorObj.addDataCursorListener(); dataCursorObj.setLineColor(Color.BLACK); Font theTitleFont = new Font("SansSerif", Font.BOLD,16); ChartTitle mainTitle = new ChartTitle(pTransform1, theTitleFont, "Data Cursors"); mainTitle.setTitleType(ChartConstants.CHART_HEADER); mainTitle.setTitlePosition( ChartConstants.CENTER_GRAPH); gWG.addChartObject(mainTitle);
Font subheadFont = new Font("SansSerif", Font.BOLD,12); ChartTitle subhead = new ChartTitle(pTransform1, subheadFont, "Click and drag the mouse"); subhead.setTitleType(ChartConstants.CHART_SUBHEAD); subhead.setTitlePosition( ChartConstants.CENTER_GRAPH); gWG.addChartObject(subhead);
Font theFooterFont = new Font("SansSerif", Font.BOLD,12); ChartTitle footer = new ChartTitle(pTransform1, theFooterFont, "There are 5 data cursor and data marker styles: a vertical line, a horizontal line, both horizontal" + "\n" + "and vertical lines (used here as the data cursor), cross hair, and box (used here as a data marker)"); footer.setTitleType(ChartConstants.CHART_FOOTER); footer.setTitlePosition( ChartConstants.CENTER_GRAPH); footer.setTitleOffset(8); gWG.addChartObject(footer); } }
|
|
|
quinncurtis
1586 Posts |
Posted - 14 Oct 2014 : 15:28:10
|
There are no known bugs in the DataCursor class. We cannot reproduce the problem you describe using our any of our example programs.
Please clarify if the problem exists in testing our DataCursorsAndMarkers example program EXACTLY as written:
Unmodified using the default MARKER_BOX data cursor ?
Modified to use the MARKER_VLINE cursor ?
Or does the problem only exist in your version of the program? In that case, does it only fail for the MARKER_VLINE, or does it fail for all cursor types? We need to determine if the problem is in our code, or in your implementation.
|
|
|
quinncurtis
1586 Posts |
Posted - 14 Oct 2014 : 15:56:49
|
I googled the error you describe, and it appears to be a Java bug, specifically associated with the first display of an object in XOR mode with AntiAliasing. You can read about it here: https://bugs.openjdk.java.net/browse/JDK-8041647
The error only appears in the debugger, it does not take the program down.
It seems to happen only on some graphics adapters.
A solution seems to be turning AntiAliasing off initially.
In the main chart setup method insert the following code.
RenderingHints currenthints = gWG.getRenderingHints(); RenderingHints hint = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); currenthints.add(hint); gWG.setRenderingHints(currenthints); See if that removes the error. |
|
|
png
USA
6 Posts |
Posted - 15 Oct 2014 : 12:47:32
|
Hello,
I added the code as suggested in previous post but am still getting the error. Is it possible to catch this error and ignore it from within your code because I cannot do so from my end? |
|
|
quinncurtis
1586 Posts |
Posted - 15 Oct 2014 : 13:52:19
|
Subclass the DataCursor class (CustomDataCursor), and override the mousePressed method with a version which places the super.mousePressed call to the base class in a try block for throwable events. This should circumvent the error. Use the CustomDataCursor class in your program in place of DataCursor. You can get rid of the rendering hints stuff. Let us know the results.
class CustomDataCursor extends DataCursor {
public CustomDataCursor(ChartView achartview, CartesianCoordinates thetransform,
int nmarkertype,
double rsize)
{
super(achartview, thetransform, nmarkertype, rsize);
}
// override mousePressed method in order to add try block
public void mousePressed(MouseEvent event)
{
try {
super.mousePressed(event);
}
catch (Throwable e )
{
}
}
}
.
.
.
.
.
CustomDataCursor dataCursorObj = new CustomDataCursor( gWG, pTransform1,
ChartConstants.MARKER_VLINE, 14.0);
dataCursorObj.setDataCursorEnable(true);
dataCursorObj.addDataCursorListener();
|
|
|
png
USA
6 Posts |
Posted - 16 Oct 2014 : 17:14:39
|
That works! Thanks very much. |
|
|
|
Topic |
|
|
|