Dookie Posted October 4, 2017 Share Posted October 4, 2017 Java Pie Chart Am considerat sa fac acest tutorial, intrucat un grafic de tip 'pie' poate fi foarte util in numeroase domenii. Intr-un grafic de tip 'pie' lungimea arcului de cer per sector este proportional cu cantitatea pe care o reprezinta. In urmatorul exemplu, folosim un Java servlet pentru a crea un graf de tip Pie. Graficul va fi randat intr-un browser. package com.zetcode.servletchart; import java.awt.BasicStroke; import java.awt.Color; import java.io.IOException; import java.io.OutputStream; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartUtilities; import org.jfree.chart.JFreeChart; import org.jfree.data.general.DefaultPieDataset; @WebServlet(name = "DoChart", urlPatterns = {"/DoChart"}) public class DoChart extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("image/png"); OutputStream outputStream = response.getOutputStream(); JFreeChart chart = getChart(); int width = 500; int height = 350; ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); } public JFreeChart getChart() { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("Croatia", 22); dataset.setValue("Bohemia", 34); dataset.setValue("Bulgaria", 18); dataset.setValue("Spain", 5); dataset.setValue("Others", 21); JFreeChart chart = ChartFactory.createPieChart("Popular destinations", dataset, true, false, false); chart.setBorderVisible(false); return chart; } } setContentType seteaza continutul pe o imagine PNG. response.setContentType("image/png"); Folosind functia getOutputStream() obtinem o metoda de transmitere a informatiei. Un 'tunel' prin care transmitem informatie. OutputStream outputStream = response.getOutputStream(); Daca aveti nelamuriri va rog sa imi lasati aici in comentarii. Daca doriti puteti sa imi trimiteti PM cu aplicatii C/C++/JavaScript/HTML/CSS/C#/Pascal si voi incerca sa va explic cat mai pe inteles. O zi placuta in continuare si spor. 1 Link to comment Share on other sites More sharing options...
South HawKing Posted October 4, 2017 Share Posted October 4, 2017 Felicitari pentru munca depusa! Link to comment Share on other sites More sharing options...
Cdorsu Posted October 7, 2017 Share Posted October 7, 2017 (edited) @Dookie, mi se pare cam greu de "digerat". Incearca sa adaugi mai multe explicatii. Ai cumva vreo legatura cu ZetCode? S-a postat un tutorial asemanator acolo in aceeasi zi. @GF HawKing, poate o sa vina ziua cand n-o sa mai postezi in topicuri doar pentru +1 ... Edited October 7, 2017 by Cdorsu Link to comment Share on other sites More sharing options...
Dookie Posted October 8, 2017 Author Share Posted October 8, 2017 @Cdorsu nu, n-are legatura cu ZetCode, cat despre explicatii sure, la urmatorul topic voi fi mai explicit. Noroc! Poti da T/C, nu cred ca mai are rost sa fie deschis. Link to comment Share on other sites More sharing options...
Cdorsu Posted October 8, 2017 Share Posted October 8, 2017 Link to comment Share on other sites More sharing options...
Recommended Posts