How to draw arrows?

Copy the following code draws a simple chart of the XYLine
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class XyChart extends Application {

    @Override
    public void start(Stage stage) {
       stage.setTitle("Line plot");
        
       final CategoryAxis xAxis = new CategoryAxis();
       final NumberAxis yAxis = new NumberAxis(1, 21,0.1);
       
       yAxis.setTickUnit(1);
       yAxis.setPrefWidth(35);
       yAxis.setMinorTickCount(10);
           
       yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis){
            @Override
        public String toString(Number object){
                String label;
                label = String.format("%7.2f", object.floatValue());
                return label;
        }
    });
final LineChart<String, Number>lineChart = new LineChart<String, Number>(xAxis, yAxis);

       lineChart.setCreateSymbols(false);
       lineChart.setAlternativeRowFillVisible(false);
       lineChart.setLegendVisible(false);
               
       XYChart.Series series1 = new XYChart.Series();
        
        series1.getData().add(new XYChart.Data("Jan", 1));
        series1.getData().add(new XYChart.Data("Feb", 4));
        series1.getData().add(new XYChart.Data("Mar", 2.5));
        series1.getData().add(new XYChart.Data("Apr", 5));
        series1.getData().add(new XYChart.Data("May", 6));
        series1.getData().add(new XYChart.Data("Jun", 8));
        series1.getData().add(new XYChart.Data("Jul", 12));
        series1.getData().add(new XYChart.Data("Aug", 8));
        series1.getData().add(new XYChart.Data("Sep", 11));
        series1.getData().add(new XYChart.Data("Oct", 13));
        series1.getData().add(new XYChart.Data("Nov", 10));
        series1.getData().add(new XYChart.Data("Dec", 20));
 
        BorderPane pane = new BorderPane();
        pane.setCenter(lineChart);          
        Scene scene = new Scene(pane, 800, 600);
        lineChart.setAnimated(false);
        lineChart.getData().addAll(series1);       
         
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }   
}
I like to shoot arrows on the table by left click of the mouse button and moved, as in this example

[http://s8.postimage.org/5xgu0j6kl/A02480.png]

How to do this?

Thank you!

Published by: 932518 on November 6, 2012 4.32

Hello. It is possible to shoot arrows on a chart. Please try the updated example the:

 import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.LineTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import javafx.scene.shape.Polygon;
import javafx.stage.Stage;

public class XyChart extends Application {
     Path path;
     BorderPane pane = new BorderPane();
    double startx = 0;
    double starty = 0;
    double endx = 0;
    double endy = 0;

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage) {

        final CategoryAxis xAxis = new CategoryAxis();
        final NumberAxis yAxis = new NumberAxis(1, 21, 0.1);
        yAxis.setTickUnit(1);
        yAxis.setPrefWidth(35);
        yAxis.setMinorTickCount(10);
        yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis) {
            @Override
            public String toString(Number object) {
                String label;
                label = String.format("%7.2f", object.floatValue());
                return label;
            }
        });
        final LineChart lineChart = new LineChart(xAxis, yAxis);

        lineChart.setCreateSymbols(false);
        lineChart.setAlternativeRowFillVisible(false);
        lineChart.setLegendVisible(false);

        XYChart.Series series1 = new XYChart.Series();

        series1.getData().add(new XYChart.Data("Jan", 1));
        series1.getData().add(new XYChart.Data("Feb", 4));
        series1.getData().add(new XYChart.Data("Mar", 2.5));
        series1.getData().add(new XYChart.Data("Apr", 5));
        series1.getData().add(new XYChart.Data("May", 6));
        series1.getData().add(new XYChart.Data("Jun", 8));
        series1.getData().add(new XYChart.Data("Jul", 12));
        series1.getData().add(new XYChart.Data("Aug", 8));
        series1.getData().add(new XYChart.Data("Sep", 11));
        series1.getData().add(new XYChart.Data("Oct", 13));
        series1.getData().add(new XYChart.Data("Nov", 10));
        series1.getData().add(new XYChart.Data("Dec", 20));

        pane.setCenter(lineChart);
        Scene scene = new Scene(pane, 800, 600);
        lineChart.setAnimated(false);
        lineChart.getData().addAll(series1);

         path = new Path();
          path.setStrokeWidth(1);
        path.setStroke(Color.BLACK);

        scene.setOnMouseReleased(mHandler);
        scene.setOnMousePressed(mHandler);
        pane.getChildren().add(path);
        stage.setScene(scene);
        stage.show();
    }
    EventHandler mHandler = new EventHandler() {
        @Override
        public void handle(MouseEvent me) {

            if (me.getEventType() == MouseEvent.MOUSE_PRESSED) {
                startx = me.getX();
                starty = me.getY();
                path.getElements().add(new MoveTo(startx, starty));

            } else if (me.getEventType() == MouseEvent.MOUSE_RELEASED) {
                endx = me.getX();
                endy = me.getY();
                path.getElements().add(new LineTo(endx, endy));

                Polygon arrow = new Polygon();
                arrow.getPoints().addAll(new Double[]{
                            0.0, 5.0,
                            -5.0, -5.0,
                            5.0, -5.0});

                double angle = Math.atan2(endy - starty, endx - startx) * 180 / 3.14;

                arrow.setRotate((angle - 90));

                arrow.setTranslateX(startx);
                arrow.setTranslateY(starty);

                arrow.setTranslateX(endx);
                arrow.setTranslateY(endy);

                pane.getChildren().add(arrow);

            }

        }
    };
}

Tags: Java

Similar Questions

  • Learn how to draw correctly

    You guys should learn how to draw your windows properly on the screen. There is a company called Microsoft which makes my operating system, the guys maybe you should contact them and get advice.

    I'm using the latest drivers from Microsoft. Can you ask them to fix the drivers? / s

  • How to draw a box under a trace of waveform?

    Hi all

    I have a graph of waveform of 3000 point showing a series of peaks.  For one of these peaks, for which I know the beginning and end clues, I would draw a box under the waveform on the graph, to highlight its position programmatically.  I don't know if there is a way to do it.

    I figured out how to draw cursors at the beginning and at the end, but finally I do for multiple peaks, and forest of cursors quickly becomes confused.  A simple shaded box works much better.

    Any ideas?

    Many thanks in advance,

    RipRock99

    A great thank you GerdW!

    The code LV was very close to what I wanted to do and is easy to use to determine how to make my code produces the result I wanted.  Basically, I added another form of wave to my chart, using my known indices x to set the values of Y for the areas I wanted to be gray as + infinity and leaving the rest to =-infinity.  I then plotted this second graph on top of the original waveform and the property node to set the fill indicator for - infinite.

    That does not answer the general question of how to draw a filled rectangle with the coordinates on a graph, but this does not fix what I wanted to achieve.

    Bravo and thanks,

    RipRock99

    PS: I'm including a preview of the result and a snapshot of the code used to define the property node programmatically.  I do not understand my code just as it is complicated, and I would also need to add a large set of data.  I hope that the pictures are enough to help someone else referencing this Council!

  • How to draw all the info my old to my new laptop computor

    Original title: draw all the information in my old laptop to the new

    How to draw all the info my old to my new laptop computor

    Hello

    1. What are the operating systems installed on both computers?

    2 you want to transfer all the settings from the old computer to the new computer?

    You can use Windows Easy Transfer to perform the task.

    http://Windows.Microsoft.com/en-us/Windows7/products/features/Windows-easy-transfer

    Hope this information helps

  • How to draw graph wrt times

    I m new to labveiw and this forum... anyone can tell how to draw simple

    graphic analog I / p with respect to time...?

    Why don't you do something like that? After the back if you have any questions.

  • How to draw the symbol of the avalanche diode in multisim?

    Hi all

    I include a symbol for the network of diodes in multisim. SP0503BAHT, can someone offer you please how to draw it? I am very new to multisim.

    Thank you

    Hello

    The approach the simplest way to do this is to copy the symbol of a diode of the database and then change the symbol to meet your needs.

    In the wizard components, when you are prompted to enter symbol information, click copy of DB and choose a diode symbol you like. Click on Edit and then you can change the symbol.

    I hope this helps.

  • How to draw or change an icon?

    How to draw, edit, convert or create an icon for folders?

    Here is a link to a bunch of programs that seek to change or create icons (and some are free): http://graphicssoft.about.com/od/iconeditorswindows/Icon_Cursor_Editors_for_Windows.htm.

    Here's a quick article on how to change folder icons (it is relatively easy) once you have created an icon you like: http://www.chami.com/tips/windows/122696W.html.

    I hope this helps.

    Good luck! Lorien - MCSA/MCSE/network + / A +.

  • How to draw a table field

    can we say, learn how to draw a table in the bb, thank you

    Hello

    Take a look at this link

    http://www.BlackBerry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800508/...

  • How to draw the graph of output?

    Hello

    How to draw the graph of an exit? is there any api for it?

    The short answer is that there is no API, but you can create your own field if you want to, and here are some samples:

    http://supportforums.BlackBerry.com/T5/Java-development/create-graph-fields/Ta-p/444968

    I recommend the search before you ask questions to see if other people have asked similar questions.  If you type chart in the search box you will find other similar topics.

  • How to draw text bordered on Bitmap usgin class Graphics?

    Hi guys.

    I'm drawing text on a line graph.

    Here is the example.

    The text color is black. Border is white (edge of letters).

    How to draw like this?

    Thanks in advance.

    If you are interested in a vaguely similar effect, but without all the subtle shadows, I have a suggestion. Draw the white text, several times, gap between the nominal position of a pixel or two in different directions and then draw the text in black at the nominal position. The idea is that white copies create an enlargement of each letter which becomes an overview when you draw the black letter on it. You may need to do this a letter at a time, allowing more space between the letters, rather than draw the entire chain at the same time.

  • How to draw an image with reflection effect?

    Hi!, someone know how to draw an image with reflex effect?. I develop in JDE 4.7 with the simulator of the storm. I want to put a picture below a reflex effect as Apple Inc. and normal. My request is a CLDC and I use a MainScrren class, this is an example of what I want to draw:

    Angel

    Hello

    I found the code on the net, it works very well on j2me that even can be used also in blackberry below.

    public static Image createShadow(Image image) {
    
            int newX = image.getWidth();
            int newY = image.getHeight()/2;
             int out[] = new int[newX*newY];
             int row[] = new int[newX];
    
            for (int iy = 0; iy < newY; iy++)
            {
              image.getRGB(row,0,newX,0,iy+newY,newX,1);
              for (int i = 0; i < row.length; i++) {
                  out[((newY-1)*newX-iy*newX)+i] = row[i] & ( (127*iy/newY)<< 24 | 0xffffff);
              }
            }
    
            return Image.createRGBImage(out,newX,newY,true);
        }
    

    Hope this will solve you problem.

    Please let me know if it solves your problem or not.

  • How to draw a video icon at the top of the image in Photoshop

    Hi team,

    Could you please tell how to draw the video icon (circle or square with triangle in the Center) at the top of the image in Photoshop? I am beginner so detailed step will be appreciated.

    Thank you very much in advance,

    Concerning

    Marianna

    Thanks Melissa. I also found another way to do it, if we have a video icon. Open the image you want to put the video icon on the top. After go to file-> Placed bound. Icon position to your liking and save.

  • Bought the creative cloud Adobe $ 20 / month, but I do not know how to draw in it. [was: Please help me... totally lost I think I want a refund.]

    I bought the creative cloud Adobe $ 20 / month, but I do not know how to draw in it. I don't have any other products Adobe or Photoshop?

    All said 'CC', but I can't find Photoshop Elements or CS6. Mine is broken? I bought it directly on the site of Photoshop, but I'm so lost. I tried following tutorial, but that does not open the drawing program. On deviantart, it says that I need to buy the product for $80 and pay a monthly fee on that as well as keep the CC $20 of Adobe to use drawing software? I wasn't aware of this how can I get a refund.

    Hi Corinne,.

    Creative cloud has no Photo Shop elements.

    You can get the version of CS6 from here: download and install creative Cloud applications .

    Concerning

    Stéphane

  • How to draw the 3D dice?

    Anyone know of a tutorial or an example to learn how to draw the 3D dice in Adobe Illustrator?

    I actually found a link to a tutorial on how to do it, but don't know if the announcement of such a link is allowed in the forum. (I'm new here.) He quite far up to a certain time and then it becomes unclear how one of the steps, or I don't know enough yet about using Illustrator to understand what he says to do. In any case, I get so far and then I can not look polished. I understand the basics for creating a drawing in 3 dimensions, so don't looking for this.

    OK, I got quite a breakthrough!

    I went ahead and have materialized to where I got the same result as above, where only the side '6' watch points, while the other two are blue.

    But then I was playing with the outline, making visible/invisible parts. That's when I noticed, there was the '4' and '5', but they were BEHIND the blue. Not before blue as I expected.

    It's simple. Only, I selected the two blue faces and used object/rearrange/send backward to position behind the faces dotted.

    After that, I was also able to select the blue edges and put a radiant on them. It is not yet exactly as this step in the tutorial, not until I find how the gradient tool. But I'm certainly happen.

    At this point, it looks like:

    And that is a SIGNIFICANT improvement on what I had before, if I say so myself. At this point, I'm probably on my way to following through with the tutorial, I started from.

  • How to draw a circle in photoshop using vbs

    How to draw a circle in photoshop using script, do not pathitems

    You don't want to use a shape layer? You can use scriptlistener to record make a circle for it, then put in a variable for values. You can also use scriptlistener to make a round selection and then caress than. You could also do a bunch of small round pieces that you can fill out and then use a little math to place a series of them in a circle.

Maybe you are looking for

  • Save images in table

    Hi all I know this has been asked before, and I read a lot of solutions, so I added a bit of detail to clarify the question... LabVIEW 2013 SP1 Vision Assistant 2013 SP1 PCIe-1433 camera link Frame Grabber Camera link, 280 fps I had an application th

  • dylanscotboy22500

    I have the windows ultra vista how can I system restore on my computer.

  • Cannot remove a faulty police

    So, I noticed that a handful of fonts on my computer seems to be broken or damaged in some way so that when I scroll through fonts in Adobe Illustrator, if I landed on these specific fonts, Illustrator can get mad and pull me back to the first font o

  • How can I reset my password without password reboot disc or flash drive?

    OT: I forgot my login. How can I reset my password without password reboot disk or flash drive. I screen login password, but it won't let me connect

  • Jump to another screen.

    How can I skip to another screen on the by clicking the button. What should I do about the event by clicking on a button.