สร้าง Flowchart Java

ผังงานสามารถเป็นประโยชน์ในการทำความเข้าใจอัลกอริทึมทีละขั้นตอนในการออกแบบการแสดงกราฟิกของเวิร์กโฟลว์และกระบวนการต่างๆ ในบางสถานการณ์ คุณอาจต้องสร้างผังงานสำหรับการแก้ปัญหา บทความนี้ครอบคลุมวิธีการสร้างไดอะแกรมผังงานโดยทางโปรแกรมใน Java

ติดตั้ง Java API เพื่อสร้าง Flowchart Diagram

คุณสามารถสร้างไดอะแกรมผังงานได้โดยใช้ API Aspose.Diagram for Java รองรับการสร้างหรือแก้ไขไฟล์ Visio ใน VSD, VSDX และ รูปแบบที่รองรับ อื่นๆ คุณสามารถติดตั้ง API ได้ง่ายๆ โดยดาวน์โหลดไฟล์ JAR จากส่วน New Releases หรือใช้ข้อมูลจำเพาะของ Maven ต่อไปนี้:

พื้นที่เก็บข้อมูล:

 <repositories>
    <repository>
        <id>AsposeJavaAPI</id>
        <name>Aspose Java API</name>
        <url>http://repository.aspose.com/repo/</url>
    </repository>
</repositories>

การพึ่งพา:

 <dependencies>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-diagram</artifactId>
        <version>22.1</version>
        <classifier>jdk16</classifier>
    </dependency>
</dependencies>

สร้าง Flowchart โดยทางโปรแกรมใน Java

คุณสามารถสร้างผังงานเพื่ออธิบายขั้นตอนของลำดับ คุณต้องทำตามขั้นตอนด้านล่างเพื่อสร้างผังงาน:

  1. ขั้นแรก สร้างสคีมาสำหรับสร้างไดอะแกรม
  2. ประการที่สอง โหลดไฟล์ VSS เป็นไฟล์หลักสำหรับเพิ่มรูปร่าง โดยใช้คลาส Diagram
  3. การเพิ่มรูปร่างและตัวเชื่อมต่อจากสคีมา
  4. กำหนดเค้าโครงสำหรับไดอะแกรมผังงาน
  5. สุดท้าย เขียนไฟล์เอาต์พุตด้วยผังงานในรูปแบบ VSDX โดยใช้วิธี บันทึก

ตัวอย่างโค้ดด้านล่างอธิบายวิธีการสร้างไดอะแกรมผังงานโดยทางโปรแกรมใน Java:

// สร้างไดอะแกรมใหม่ 
int pageNumber = 0;
String rectangleMaster = "Process", decisionMaster = "Decision", connectorMaster = "Dynamic connector"; 

Diagram diagram = new Diagram("XANFLOWCHARTNEW.vss"); 

double width = 1, height = 1, pinX = 4, pinY = 10; 
long process1 = diagram.addShape(pinX, pinY, width, height, rectangleMaster, 0); 
Shape processShape1 = diagram.getPages().getPage(pageNumber).getShapes().getShape(process1); 

processShape1.getText().getValue().add(new Txt("PROCESS")); 
processShape1.setName("PROCESS"); 
processShape1.getXForm().getLocPinX().getUfe().setF("Width*0.5"); 
processShape1.getXForm().getLocPinY().getUfe().setF("Height*0.5"); 

pinY = pinY - 2; 

long decision1 = diagram.addShape(pinX, pinY, width, height, decisionMaster, 0);
Shape decisionShape1 = diagram.getPages().getPage(pageNumber).getShapes().getShape(decision1);

decisionShape1.getText().getValue().add(new Txt("DECISION")); 
decisionShape1.setName("DECISION"); 
decisionShape1.getXForm().getLocPinX().getUfe().setF("Width*0.5"); 
decisionShape1.getXForm().getLocPinY().getUfe().setF("Height*0.5"); 

pinY = pinY - 2; 
long process2 = diagram.addShape(pinX, pinY, width, height, rectangleMaster, 0); 
Shape processShape2 = diagram.getPages().getPage(pageNumber).getShapes().getShape(process2);

processShape2.getText().getValue().add(new Txt("PROCESS")); 
processShape2.setName("PROCESS");
processShape2.getXForm().getLocPinX().getUfe().setF("Width*0.5");
processShape2.getXForm().getLocPinY().getUfe().setF("Height*0.5"); 

pinY = pinY - 2; 
long process3 = diagram.addShape(pinX, pinY, width, height, rectangleMaster, 0);
Shape processShape3 = diagram.getPages().getPage(pageNumber).getShapes().getShape(process3);

processShape3.getText().getValue().add(new Txt("PROCESS")); 
processShape3.setName("PROCESS");
processShape3.getXForm().getLocPinX().getUfe().setF("Width*0.5");
processShape3.getXForm().getLocPinY().getUfe().setF("Height*0.5"); 

pinY = pinY - 2; 
long process4 = diagram.addShape(pinX, pinY, width, height, rectangleMaster, 0);
Shape processShape4 = diagram.getPages().getPage(pageNumber).getShapes().getShape(process4);

processShape4.getText().getValue().add(new Txt("PROCESS")); 
processShape4.setName("PROCESS");
processShape4.getXForm().getLocPinX().getUfe().setF("Width*0.5");
processShape4.getXForm().getLocPinY().getUfe().setF("Height*0.5"); 

long connecterId = diagram.addShape(new Shape(), connectorMaster, 0);
diagram.getPages().getPage(pageNumber).connectShapesViaConnector(process1, ConnectionPointPlace.BOTTOM, 
        decision1, ConnectionPointPlace.TOP, connecterId); 

long connecterId1 = diagram.addShape(new Shape(), connectorMaster, 0);
diagram.getPages().getPage(pageNumber).connectShapesViaConnector(decision1, ConnectionPointPlace.BOTTOM,
        process2, ConnectionPointPlace.TOP, connecterId1); 

long connecterId2 = diagram.addShape(new Shape(), connectorMaster, 0);
diagram.getPages().getPage(pageNumber).connectShapesViaConnector(process2, ConnectionPointPlace.BOTTOM,
        process3, ConnectionPointPlace.TOP, connecterId2); 

long connecterId3 = diagram.addShape(new Shape(), connectorMaster, 0);
diagram.getPages().getPage(pageNumber).connectShapesViaConnector(process3, ConnectionPointPlace.BOTTOM,
        process4, ConnectionPointPlace.TOP, connecterId3); 

long connecterId4 = diagram.addShape(new Shape(), connectorMaster, 0);
diagram.getPages().getPage(pageNumber).connectShapesViaConnector(decision1, ConnectionPointPlace.RIGHT,
        process4, ConnectionPointPlace.TOP, connecterId4);

// ตั้งค่าตัวเลือกเค้าโครงอัตโนมัติ
LayoutOptions layoutOptions = new LayoutOptions();

// วิธี 
layoutOptions.setLayoutStyle(LayoutStyle.FLOW_CHART);
layoutOptions.setDirection(LayoutDirection.BOTTOM_TO_TOP);
diagram.layout(layoutOptions);

DiagramSaveOptions options = new DiagramSaveOptions(SaveFileFormat.VSDX);
diagram.save("sample.vsdx", options);

ตัวอย่างผังงานแสดงตัวอย่าง

Flowchart Creator Maker Java

นอกจากนี้ คุณอาจต้องการ ดาวน์โหลด ไฟล์อินพุตและเอาต์พุตเพื่อตรวจสอบคุณสมบัตินี้

รับใบอนุญาต API ฟรี

คุณสามารถประเมินคุณลักษณะทั้งหมดของ API ได้โดยไม่มีข้อจำกัดใดๆ โดยขอ ใบอนุญาตชั่วคราวฟรี

บทสรุป

โดยสรุป คุณได้เรียนรู้วิธีสร้างหรือสร้างผังงานโดยใช้โปรแกรมโดยใช้ Java คุณสามารถปรับแต่งและเปลี่ยนทิศทางหรือรูปร่างของผังงานได้ตามความต้องการของคุณ คุณจึงสามารถฝังคุณสมบัตินี้ได้อย่างง่ายดายโดยใช้การเรียก API จากภายในแอปพลิเคชัน Java ของคุณ นอกจากนี้ คุณสามารถไปที่ API เอกสารประกอบ เพื่อตรวจสอบคุณสมบัติอื่นๆ ของ API คุณสามารถถามคำถามใดๆ ได้โดยติดต่อที่ ฟอรัม

ดูสิ่งนี้ด้วย