[Gvsig_desarrolladores] Chart api

José Badía jbadia en scolab.es
Mie Nov 4 13:29:52 CET 2015


Hi,

documentation is not available at this moment because we are migrating old
plone Web.

Above this lines, I describe the most useful recipes about chart methods.
To insert data in the charts take a look to the ChartDataSet class.

Chart persistence is controlled by gvSIG and all the charts created will be
saved in the same way as the other documents (views, maps, tables,...)


- Listing the registered chart services

The different chart types availables on this extension are defined and
registered in the org.gvsig.chart.base package.

If it's useful to know which ones are registered on the application, it's
possible to obtain a list of them using this procedure:

/* Getting the manager dedicated to adminiter the extension chart services */
ChartServiceManager serviceManager = ChartLocator.getServiceManager();
/* Obtaining the list with the registered services */
List<ChartService> registeredServices = serviceManager.getChartServices();

- Creating a single chart of a registered service

Using the service manager, it's possible to create a chart of a specific
type (always if it's in the registered previously)

To generate it, first of all is needed to create its properties, to
configure it. After that, the associated service will be generated (the
chart in this case) according to the properties type.

There's an example about a Pie chart initialization with the default
parameters:

/* Getting the manager dedicated to adminiter the extension chart services  */
ChartServiceManager serviceManager = ChartLocator.getServiceManager();
/* Creating a properties of a Pie chart type */
ChartProperties chartProperties =
serviceManager.getChartManager().createProperties(PieChart.class.getSimpleName());
/* Here it's possible to modify/edit the default values, before
creating the service */
chartProperties.setChartTitle("Población");
chartProperties.setChartDescription("Gráfico de tartas de los
habitantes de cada población de la Comunidad Valenciana");// …
/* And finally, creating the service */
ChartService grafico =
serviceManager.getChartManager().createChart(chartProperties)

- Creating a multiple chart.

The multiple chart (OverlyaChart) let us to overlay and to establish
relationships between several simple charts. Each simple chart can
represent a data variable such as temerature, population, area, etc.

Assuming that variables *grafico1* and *grafico2* are generated by the
previous process especified lines above, the procedure to create a multiple
chart will be teh following:

/* Getting the manager dedicated to adminiter the extension chart services */
ChartServiceManager serviceManager = ChartLocator.getServiceManager();
/* Creating a multiple chart */
ChartService grafico_compuesto =
serviceManager.getChartManager().createGroupedCharts();
/* Adding the simple charts to the multiple */
grafico_compuesto.addChartService(grafico1);
grafico_compuesto.addChartService(grafico2);

- Drawing a chart

When the service is prepared (it doesn't matter if it's simple or
multiple), the following step will be draw it over a panel.

/* Panel where the graph will be drawn */
Jpanel panel = new Jpanel();
/* The 'grafico' variable has the specific service. If it's a multiple
chart, it will paint each one over the others */
grafico.draw(panel.getGraphics(), panel.getBounds());


- Creating the multiple chart editor panel

Multiple chart is composed by one or more variables. Each one is a chart
that represents a data set. It lets to overlay several charts to establish
erlationships between them or to represent a more complete information in
the chart. The Swing part of the extension provides a panel that allows to
manipulate and manage this multiple chart using a graphical interface.

Assuming that *grafico_compuesto* is a multiple chart created and
initializated, the proceduer will be the following:

/* Panel where the multiple chart form will be placed */
Jpanel panel = new Jpanel();
/* Obtaining the SWING manager of the extension */
ChartSwingManager chartSwingManager =
ChartSwingLocator.getSwingManager().getChartSwingManager();
/* Creating the form and associating it to the grafico_compuesto
variable previously created */
EditorGroupedChartPanel editorPanel =
chartSwingManager.createEditorChartPanel(grafico_compuesto);
/* Adding the editor to the panel */
panel.add(editorPanel.getComponent());

- Wizard to create or edit a chart service

The Swing part of this extension also provides a way to edit and assign the
chart properties using a graphical interface.

/* Obtaining the SWING manager of the extension */
ChartSwingManager swingManager =
ChartSwingLocator.getSwingManager().getChartSwingManager();
/* Creating a new instance of the wizard to create a new service*/
EditorChartServicePanel editorChartServicePanel =
swingManager.createNewChartPanel();
/* The form will be added to a special JDialog that returns the
service created using the values indicated in the form (or null if
there is an error) */
ChartService service =  EditorChartServiceJDialog.showDialog(
      "Add_new_variable",
      editorChartServicePanel);
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: http://listserv.gva.es/pipermail/gvsig_desarrolladores/attachments/20151104/e89a84c1/attachment.htm 


Más información sobre la lista de distribución gvSIG_desarrolladores