2011-07-06 4 views
0

J'utilise Jfreechart pour dessiner l'axe x-y Je veux dessiner un rectangle et un cercle sur cet axe x-y. Savez-vous comment c'est possible? Y at-il un meilleur moyen (plutôt que jfreechart) pour dessiner l'axe x-y et ses formes sur lui?dessiner des formes dans jfreechart

+0

Voulez-vous dire quelque chose sur le graphique? – trashgod

+0

Je veux dessiner un cercle et un rectangle sur un graphique. Comment dois-je le faire? – SunyGirl

+0

Voulez-vous dire que vous voulez construire un ensemble de données dont les points forment un cercle et un carré en deux dimensions? – trashgod

Répondre

0

Je dessine des cercles ou d'autres éléments sur un diagramme de diagramme XY avec la capacité d'annotation. Pour ajouter un cercle, utilisez "addAnnotation (XYShapeAnnotation (new Ellipse2D.Double (...)))" par exemple. Voici un exemple de méthode:

public void markChartAt2(float fromX, float fromY, float toX, float toY, markType markerTyp, Color lineColor, String toolTip) { 
    XYLineAnnotation lineAnnotation; 
    XYShapeAnnotation shapeAnnotation; 
    if (lineColor == null) 
     lineColor = Color.black; 
    maxY = yAxis.getUpperBound(); 
    minY = yAxis.getLowerBound(); 
    yFactor = (maxY - minY) * .005d; 
    maxX = xAxis.getUpperBound(); 
    minX = xAxis.getLowerBound(); 
    xFactor = (maxX - minX) * .0005d;  
    switch (markerTyp){ 
    case CIRCLE: 
     shapeAnnotation = new XYShapeAnnotation(
       new Ellipse2D.Double(fromX - xFactor, fromY - yFactor, xFactor+xFactor, yFactor+yFactor), 
       markerLineWidth, lineColor) ; 
     shapeAnnotation.setToolTipText(toolTip); 
     priceXYPlot.addAnnotation(shapeAnnotation); 
     break; 
    case SQUARE: 
     shapeAnnotation = new XYShapeAnnotation(
       new Rectangle2D.Double(fromX - xFactor, fromY - yFactor, xFactor+xFactor, yFactor+yFactor), 
       markerLineWidth, lineColor); 
     shapeAnnotation.setToolTipText(toolTip); 
     priceXYPlot.addAnnotation(shapeAnnotation); 
     break; 
    } 
} 
+0

Vous devriez ajouter une explication à votre exemple de code qui explique comment cela aide à résoudre le problème du PO. – moggi

+0

Mise à jour de ma réponse pour expliquer comment dessiner un rectangle ou un cercle à l'aide de la méthode addAnnotation() –

Questions connexes