Mantenimiento SP:
use ventas
go
/* PROCEDIMIENTOS ALMACENADOS PARA LOS DIFERENTES MANTENIMIENTOS */
IF EXISTS (SELECT 1 FROM sys.objects WHERE name = 'SP_ABC_CAJAS' AND TYPE = 'P')
DROP PROC SP_ABC_CAJAS
GO
CREATE PROC SP_ABC_CAJAS (@TIPO INT,@IDCAJA INT,@DESCRIPCION VARCHAR(10),@ESTADO CHAR(1) )
AS
IF @TIPO = 1
BEGIN
INSERT INTO CAJAS VALUES (@IDCAJA, @DESCRIPCION,@ESTADO)
END
ELSE
IF @TIPO = 2
BEGIN
DELETE FROM CAJAS
WHERE IDCAJA = @IDCAJA
END
ELSE
BEGIN
UPDATE CAJAS
SET DESCRIPCION = @DESCRIPCION
, ESTADO = @ESTADO
WHERE IDCAJA = @IDCAJA
END
GO
IF EXISTS (SELECT 1 FROM sys.objects WHERE name = 'SP_ABC_USUARIOS' AND TYPE = 'P')
DROP PROC SP_ABC_USUARIOS
GO
CREATE PROC SP_ABC_USUARIOS (@TIPO INT,@IDUSUARIO INT,@APELLIDO VARCHAR(10),@NOMBRE VARCHAR(10),@PASSWORD VARCHAR(10),@ESTADO CHAR(1), @FECHA_INGRESO DATETIME )
AS
IF @TIPO = 1
BEGIN
INSERT INTO USUARIOS VALUES (@IDUSUARIO, @APELLIDO,@NOMBRE,@PASSWORD,@ESTADO,@FECHA_INGRESO)
END
ELSE
IF @TIPO = 2
BEGIN
DELETE FROM USUARIOS
WHERE IDUSUARIO= @IDUSUARIO
END
ELSE
BEGIN
UPDATE USUARIOS
SET APELLIDO = @APELLIDO
, NOMBRE = @NOMBRE
, ESTADO = @ESTADO
, FECHA_INGRESO = @FECHA_INGRESO
WHERE IDUSUARIO = @IDUSUARIO
END
GO
IF EXISTS (SELECT 1 FROM sys.objects WHERE name = 'SP_ABC_BODEGA' AND TYPE = 'P')
DROP PROC SP_ABC_BODEGA
GO
CREATE PROC SP_ABC_BODEGA (@TIPO INT,@IDUBICACION INT,@FILA INT ,@COLUMNA INT,@DESCRIPCION VARCHAR(10),@ESTADO CHAR(1))
AS
IF @TIPO = 1
BEGIN
INSERT INTO BODEGA VALUES (@IDUBICACION, @FILA,@COLUMNA,@DESCRIPCION,@ESTADO)
END
ELSE
IF @TIPO = 2
BEGIN
DELETE FROM BODEGA
WHERE IDUBICACION= @IDUBICACION
END
ELSE
BEGIN
UPDATE BODEGA
SET FILA = @FILA
, COLUMNA = @COLUMNA
, DESCRIPCION = @DESCRIPCION
, ESTADO = @ESTADO
WHERE IDUBICACION = @IDUBICACION
END
GO
IF EXISTS (SELECT 1 FROM sys.objects WHERE name = 'SP_ABC_PROVEEDORES' AND TYPE = 'P')
DROP PROC SP_ABC_PROVEEDORES
GO
CREATE PROC SP_ABC_PROVEEDORES (@TIPO INT,@IDPROVEEDOR INT,@DESCRIPCION VARCHAR(10),@FECHA_INICIO DATETIME ,@ESTADO CHAR(1) )
AS
IF @TIPO = 1
BEGIN
INSERT INTO PROVEEDORES VALUES (@IDPROVEEDOR, @DESCRIPCION,@FECHA_INICIO,@ESTADO)
END
ELSE
IF @TIPO = 2
BEGIN
DELETE FROM PROVEEDORES
WHERE IDPROVEEDOR = @IDPROVEEDOR
END
ELSE
BEGIN
UPDATE PROVEEDORES
SET DESCRIPCION = @DESCRIPCION
, FECHA_INICIO = @FECHA_INICIO
, ESTADO = @ESTADO
WHERE IDPROVEEDOR = @IDPROVEEDOR
END
GO
IF EXISTS (SELECT 1 FROM sys.objects WHERE name = 'SP_ABC_PRODUCTOS' AND TYPE = 'P')
DROP PROC SP_ABC_PRODUCTOS
GO
CREATE PROC SP_ABC_PRODUCTOS (@TIPO INT,@IDPRODUCTO INT,@DESCRIPCION VARCHAR(10), @ESTADO CHAR(1),@PCOSTO NUMERIC (18,2),@PVENTA NUMERIC (18,2),@IDUBICACION INT,@FECHA_INGRESO DATETIME, @FECHA_CADUCA DATETIME,@IDPROVEEDOR INT,@EXISTENCIA INT,@STOCK_MIN INT , @IDUSUARIO INT )
AS
IF @TIPO = 1
BEGIN
INSERT INTO PRODUCTOS VALUES (@IDPRODUCTO, @DESCRIPCION,@ESTADO, @PCOSTO,@PVENTA,@IDUBICACION,@FECHA_INGRESO,@FECHA_CADUCA,@IDPROVEEDOR,@EXISTENCIA,@STOCK_MIN,@IDUSUARIO)
END
ELSE
IF @TIPO = 2
BEGIN
DELETE FROM PRODUCTOS
WHERE IDPROD = @IDPRODUCTO
AND IDUBICACION = @IDUBICACION
AND IDPROVEEDOR = @IDPROVEEDOR
AND IDUSUARIO = @IDUSUARIO
END
ELSE
BEGIN
UPDATE PRODUCTOS
SET DESCRIPCION = @DESCRIPCION
, ESTADO = @ESTADO
, PCOSTO = @PCOSTO
, PVENTA = @PVENTA
, FECHA_INGRESO = @FECHA_INGRESO
, FECHA_CADUCA = FECHA_CADUCA
, EXISTENCIA = @EXISTENCIA
, STOCK_MIN = @STOCK_MIN
WHERE IDPROD = @IDPRODUCTO
AND IDUBICACION = @IDUBICACION
AND IDPROVEEDOR = @IDPROVEEDOR
AND IDUSUARIO = @IDUSUARIO
END
GO
Jou'Soft
Sunday, February 3, 2013
Mantenimiento
Conexion:
Imports System.Data.SqlClient
Module conexion
Public conn As New SqlConnection()
Public Function Conecta(strUsuario As String, strPassword As String) As Boolean
Conecta = False
Try
conn.ConnectionString = "Data Source=JOUSOFT\DEVELOPER;Initial Catalog=ventas;Persist Security Info=True;User ID= " & strUsuario & ";Password= " & strPassword
conn.Open()
Conecta = True
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
End Module
Mantenimiento:
Imports System.Data.SqlClient
Public Class frmABC_Bodega
Public gintEstado As Integer
Private Sub frmABC_Bodega_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: esta línea de código carga datos en la tabla 'DataBodega.BODEGA' Puede moverla o quitarla según sea necesario.
Me.BODEGATableAdapter.Fill(Me.DataBodega.BODEGA)
End Sub
Sub Mantenimento(intOpcion As Integer)
' 1 - Alta
' 2 - Baja
' 3 - Cambio
Dim strMensaje As String
prgEstado.Value = 0
prgEstado.Maximum = 100
prgEstado.Minimum = 0
Select Case intOpcion
Case 1
strMensaje = " ingresar "
Case 2
strMensaje = " eliminar "
Case 3
strMensaje = " modificar "
Case -1
Beep()
Exit Sub
End Select
Dim strEstado As String
strEstado = cbmEstado.SelectedIndex
prgEstado.Value = prgEstado.Value + 20
Try
prgEstado.Value = prgEstado.Value + 20
Me.BODEGATableAdapter.SP_ABC_BODEGA(intOpcion, txtCodigo.Text, txtFila.Text, txtColumna.Text, txtDescripcion.Text, strEstado)
prgEstado.Value = prgEstado.Value + 20
Me.BODEGATableAdapter.Fill(Me.DataBodega.BODEGA)
Catch ex As Exception
MsgBox(ex.Message & " No se pudo " & strMensaje & " el registro ", MsgBoxStyle.Critical, "ERROR")
End Try
prgEstado.Value = prgEstado.Maximum
End Sub
Private Sub dgBodega_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgBodega.CellClick
Habilitar(2)
gintEstado = -1
Llenado(e.RowIndex)
End Sub
Public Sub Llenado(intIndex As Integer)
Try
txtCodigo.Text = dgBodega.Item(0, intIndex).Value
txtDescripcion.Text = dgBodega.Item(1, intIndex).Value
txtFila.Text = dgBodega.Item(2, intIndex).Value
txtColumna.Text = dgBodega.Item(3, intIndex).Value
If dgBodega.Item(4, intIndex).Value = 0 Then
cbmEstado.SelectedIndex = 0
Else
cbmEstado.SelectedIndex = 1
End If
Catch ex As Exception
dgBodega.FirstDisplayedScrollingRowIndex = 0
End Try
End Sub
Private Sub dgBodega_KeyDown(sender As Object, e As KeyEventArgs) Handles dgBodega.KeyDown
If e.KeyCode = Keys.Delete Then
If (MsgBox("Desea eliminar el registro ? ", vbYesNo)) Then
Mantenimento(2)
End If
End If
End Sub
Private Sub opAlta_CheckedChanged(sender As Object, e As EventArgs) Handles opAlta.CheckedChanged
gintEstado = 1
Habilitar(1)
txtCodigo.Focus()
End Sub
Private Sub opBaja_CheckedChanged(sender As Object, e As EventArgs) Handles opBaja.CheckedChanged
gintEstado = 2
Habilitar(2)
End Sub
Private Sub opCambio_CheckedChanged(sender As Object, e As EventArgs) Handles opCambio.CheckedChanged
gintEstado = 3
Habilitar(3)
txtDescripcion.Focus()
End Sub
Private Sub btnAceptar_Click(sender As Object, e As EventArgs) Handles btnAceptar.Click
Me.prgEstado.Visible = True
Mantenimento(gintEstado)
Me.prgEstado.Visible = False
Habilitar(2)
gintEstado = -1
End Sub
Public Sub Habilitar(intOpcion As Integer)
Select Case intOpcion
Case 1 'alta
Me.txtCodigo.Enabled = True
Me.txtColumna.Enabled = True
Me.txtFila.Enabled = True
Me.txtDescripcion.Enabled = True
Me.cbmEstado.Enabled = True
Case 2 ' baja
Me.txtCodigo.Enabled = False
Me.txtColumna.Enabled = False
Me.txtFila.Enabled = False
Me.txtDescripcion.Enabled = False
Me.cbmEstado.Enabled = False
Case 3 'cambio
Me.txtCodigo.Enabled = False
Me.txtColumna.Enabled = True
Me.txtFila.Enabled = True
Me.txtDescripcion.Enabled = True
Me.cbmEstado.Enabled = True
End Select
End Sub
Private Sub btnCancelar_Click(sender As Object, e As EventArgs) Handles btnCancelar.Click
Me.Close()
End Sub
Private Sub dgBodega_CurrentCellChanged(sender As Object, e As EventArgs) Handles dgBodega.CurrentCellChanged
Try
Llenado(dgBodega.CurrentCell.RowIndex)
Catch ex As Exception
End Try
End Sub
Imports System.Data.SqlClient
Module conexion
Public conn As New SqlConnection()
Public Function Conecta(strUsuario As String, strPassword As String) As Boolean
Conecta = False
Try
conn.ConnectionString = "Data Source=JOUSOFT\DEVELOPER;Initial Catalog=ventas;Persist Security Info=True;User ID= " & strUsuario & ";Password= " & strPassword
conn.Open()
Conecta = True
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
End Module
Mantenimiento:
Imports System.Data.SqlClient
Public Class frmABC_Bodega
Public gintEstado As Integer
Private Sub frmABC_Bodega_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: esta línea de código carga datos en la tabla 'DataBodega.BODEGA' Puede moverla o quitarla según sea necesario.
Me.BODEGATableAdapter.Fill(Me.DataBodega.BODEGA)
End Sub
Sub Mantenimento(intOpcion As Integer)
' 1 - Alta
' 2 - Baja
' 3 - Cambio
Dim strMensaje As String
prgEstado.Value = 0
prgEstado.Maximum = 100
prgEstado.Minimum = 0
Select Case intOpcion
Case 1
strMensaje = " ingresar "
Case 2
strMensaje = " eliminar "
Case 3
strMensaje = " modificar "
Case -1
Beep()
Exit Sub
End Select
Dim strEstado As String
strEstado = cbmEstado.SelectedIndex
prgEstado.Value = prgEstado.Value + 20
Try
prgEstado.Value = prgEstado.Value + 20
Me.BODEGATableAdapter.SP_ABC_BODEGA(intOpcion, txtCodigo.Text, txtFila.Text, txtColumna.Text, txtDescripcion.Text, strEstado)
prgEstado.Value = prgEstado.Value + 20
Me.BODEGATableAdapter.Fill(Me.DataBodega.BODEGA)
Catch ex As Exception
MsgBox(ex.Message & " No se pudo " & strMensaje & " el registro ", MsgBoxStyle.Critical, "ERROR")
End Try
prgEstado.Value = prgEstado.Maximum
End Sub
Private Sub dgBodega_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgBodega.CellClick
Habilitar(2)
gintEstado = -1
Llenado(e.RowIndex)
End Sub
Public Sub Llenado(intIndex As Integer)
Try
txtCodigo.Text = dgBodega.Item(0, intIndex).Value
txtDescripcion.Text = dgBodega.Item(1, intIndex).Value
txtFila.Text = dgBodega.Item(2, intIndex).Value
txtColumna.Text = dgBodega.Item(3, intIndex).Value
If dgBodega.Item(4, intIndex).Value = 0 Then
cbmEstado.SelectedIndex = 0
Else
cbmEstado.SelectedIndex = 1
End If
Catch ex As Exception
dgBodega.FirstDisplayedScrollingRowIndex = 0
End Try
End Sub
Private Sub dgBodega_KeyDown(sender As Object, e As KeyEventArgs) Handles dgBodega.KeyDown
If e.KeyCode = Keys.Delete Then
If (MsgBox("Desea eliminar el registro ? ", vbYesNo)) Then
Mantenimento(2)
End If
End If
End Sub
Private Sub opAlta_CheckedChanged(sender As Object, e As EventArgs) Handles opAlta.CheckedChanged
gintEstado = 1
Habilitar(1)
txtCodigo.Focus()
End Sub
Private Sub opBaja_CheckedChanged(sender As Object, e As EventArgs) Handles opBaja.CheckedChanged
gintEstado = 2
Habilitar(2)
End Sub
Private Sub opCambio_CheckedChanged(sender As Object, e As EventArgs) Handles opCambio.CheckedChanged
gintEstado = 3
Habilitar(3)
txtDescripcion.Focus()
End Sub
Private Sub btnAceptar_Click(sender As Object, e As EventArgs) Handles btnAceptar.Click
Me.prgEstado.Visible = True
Mantenimento(gintEstado)
Me.prgEstado.Visible = False
Habilitar(2)
gintEstado = -1
End Sub
Public Sub Habilitar(intOpcion As Integer)
Select Case intOpcion
Case 1 'alta
Me.txtCodigo.Enabled = True
Me.txtColumna.Enabled = True
Me.txtFila.Enabled = True
Me.txtDescripcion.Enabled = True
Me.cbmEstado.Enabled = True
Case 2 ' baja
Me.txtCodigo.Enabled = False
Me.txtColumna.Enabled = False
Me.txtFila.Enabled = False
Me.txtDescripcion.Enabled = False
Me.cbmEstado.Enabled = False
Case 3 'cambio
Me.txtCodigo.Enabled = False
Me.txtColumna.Enabled = True
Me.txtFila.Enabled = True
Me.txtDescripcion.Enabled = True
Me.cbmEstado.Enabled = True
End Select
End Sub
Private Sub btnCancelar_Click(sender As Object, e As EventArgs) Handles btnCancelar.Click
Me.Close()
End Sub
Private Sub dgBodega_CurrentCellChanged(sender As Object, e As EventArgs) Handles dgBodega.CurrentCellChanged
Try
Llenado(dgBodega.CurrentCell.RowIndex)
Catch ex As Exception
End Try
End Sub
Friday, April 23, 2010
Bueno amigos, aca les envio otra grafica muy interesante, es muy practica para cualquier informe que se quiera presentar.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ejemplos;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class BarChartDemo1 extends ApplicationFrame
{
public BarChartDemo1(String title)
{
super(title);
CategoryDataset dataset = createDataset();
JFreeChart chart = createChart(dataset);
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setFillZoomRectangle(true);
chartPanel.setMouseWheelEnabled(true);
chartPanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartPanel);
}
private static CategoryDataset createDataset()
{
String series1 = "First";
String series2 = "Second";
String series3 = "Third";
String category1 = "Category 1";
String category2 = "Category 2";
String category3 = "Category 3";
String category4 = "Category 4";
String category5 = "Category 5";
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(1.0D, series1, category1);
dataset.addValue(4.0D, series1, category2);
dataset.addValue(3.0D, series1, category3);
dataset.addValue(5.0D, series1, category4);
dataset.addValue(5.0D, series1, category5);
dataset.addValue(5.0D, series2, category1);
dataset.addValue(7.0D, series2, category2);
dataset.addValue(6.0D, series2, category3);
dataset.addValue(8.0D, series2, category4);
dataset.addValue(4.0D, series2, category5);
dataset.addValue(4.0D, series3, category1);
dataset.addValue(3.0D, series3, category2);
dataset.addValue(2.0D, series3, category3);
dataset.addValue(3.0D, series3, category4);
dataset.addValue(6.0D, series3, category5);
return dataset;
}
private static JFreeChart createChart(CategoryDataset dataset)
{
JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo 1 by Jou'Soft", "Category", "Value", dataset, PlotOrientation.VERTICAL, true, true, false);
chart.setBackgroundPaint(Color.white);
CategoryPlot plot = (CategoryPlot)chart.getPlot();
NumberAxis rangeAxis = (NumberAxis)plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
BarRenderer renderer = (BarRenderer)plot.getRenderer();
renderer.setDrawBarOutline(false);
GradientPaint gp0 = new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0, 0, 64));
GradientPaint gp1 = new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0, 64, 0));
GradientPaint gp2 = new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0));
renderer.setSeriesPaint(0, gp0);
renderer.setSeriesPaint(1, gp1);
renderer.setSeriesPaint(2, gp2);
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(0.5235987755982988D));
return chart;
}
public static void main(String[] args)
{
BarChartDemo1 demo = new BarChartDemo1("Bar Chart Demo 1 by Jou'Soft");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ejemplos;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class BarChartDemo1 extends ApplicationFrame
{
public BarChartDemo1(String title)
{
super(title);
CategoryDataset dataset = createDataset();
JFreeChart chart = createChart(dataset);
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setFillZoomRectangle(true);
chartPanel.setMouseWheelEnabled(true);
chartPanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartPanel);
}
private static CategoryDataset createDataset()
{
String series1 = "First";
String series2 = "Second";
String series3 = "Third";
String category1 = "Category 1";
String category2 = "Category 2";
String category3 = "Category 3";
String category4 = "Category 4";
String category5 = "Category 5";
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(1.0D, series1, category1);
dataset.addValue(4.0D, series1, category2);
dataset.addValue(3.0D, series1, category3);
dataset.addValue(5.0D, series1, category4);
dataset.addValue(5.0D, series1, category5);
dataset.addValue(5.0D, series2, category1);
dataset.addValue(7.0D, series2, category2);
dataset.addValue(6.0D, series2, category3);
dataset.addValue(8.0D, series2, category4);
dataset.addValue(4.0D, series2, category5);
dataset.addValue(4.0D, series3, category1);
dataset.addValue(3.0D, series3, category2);
dataset.addValue(2.0D, series3, category3);
dataset.addValue(3.0D, series3, category4);
dataset.addValue(6.0D, series3, category5);
return dataset;
}
private static JFreeChart createChart(CategoryDataset dataset)
{
JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo 1 by Jou'Soft", "Category", "Value", dataset, PlotOrientation.VERTICAL, true, true, false);
chart.setBackgroundPaint(Color.white);
CategoryPlot plot = (CategoryPlot)chart.getPlot();
NumberAxis rangeAxis = (NumberAxis)plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
BarRenderer renderer = (BarRenderer)plot.getRenderer();
renderer.setDrawBarOutline(false);
GradientPaint gp0 = new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0, 0, 64));
GradientPaint gp1 = new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0, 64, 0));
GradientPaint gp2 = new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0));
renderer.setSeriesPaint(0, gp0);
renderer.setSeriesPaint(1, gp1);
renderer.setSeriesPaint(2, gp2);
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(0.5235987755982988D));
return chart;
}
public static void main(String[] args)
{
BarChartDemo1 demo = new BarChartDemo1("Bar Chart Demo 1 by Jou'Soft");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
}
Friday, April 16, 2010
Ejemplo JfreeChart: StackedAreaChartDemo1
Bueno seguimos con la colaboracion de esta gran herramienta:
Codigo Fuente:
package ejemplos;
import java.awt.Dimension;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class StackedAreaChartDemo1 extends ApplicationFrame
{
public StackedAreaChartDemo1(String paramString)
{
super(paramString);
JPanel localJPanel = createDemoPanel();
localJPanel.setPreferredSize(new Dimension(500, 270));
setContentPane(localJPanel);
}
public static CategoryDataset createDataset()
{
DefaultCategoryDataset localDefaultCategoryDataset = new DefaultCategoryDataset();
localDefaultCategoryDataset.addValue(1.0D, "S1", "C1");
localDefaultCategoryDataset.addValue(2.0D, "S1", "C2");
localDefaultCategoryDataset.addValue(3.0D, "S1", "C3");
localDefaultCategoryDataset.addValue(4.0D, "S1", "C4");
localDefaultCategoryDataset.addValue(5.0D, "S1", "C5");
localDefaultCategoryDataset.addValue(6.0D, "S1", "C6");
localDefaultCategoryDataset.addValue(7.0D, "S1", "C7");
localDefaultCategoryDataset.addValue(8.0D, "S1", "C8");
localDefaultCategoryDataset.addValue(6.0D, "S2", "C1");
localDefaultCategoryDataset.addValue(3.0D, "S2", "C2");
localDefaultCategoryDataset.addValue(4.0D, "S2", "C3");
localDefaultCategoryDataset.addValue(3.0D, "S2", "C4");
localDefaultCategoryDataset.addValue(9.0D, "S2", "C5");
localDefaultCategoryDataset.addValue(7.0D, "S2", "C6");
localDefaultCategoryDataset.addValue(2.0D, "S2", "C7");
localDefaultCategoryDataset.addValue(3.0D, "S2", "C8");
localDefaultCategoryDataset.addValue(1.0D, "S3", "C1");
localDefaultCategoryDataset.addValue(7.0D, "S3", "C2");
localDefaultCategoryDataset.addValue(6.0D, "S3", "C3");
localDefaultCategoryDataset.addValue(7.0D, "S3", "C4");
localDefaultCategoryDataset.addValue(4.0D, "S3", "C5");
localDefaultCategoryDataset.addValue(5.0D, "S3", "C6");
localDefaultCategoryDataset.addValue(3.0D, "S3", "C7");
localDefaultCategoryDataset.addValue(1.0D, "S3", "C8");
return localDefaultCategoryDataset;
}
public static JFreeChart createChart(CategoryDataset paramCategoryDataset)
{
JFreeChart localJFreeChart = ChartFactory.createStackedAreaChart("Stacked Area Chart by (Jou'Soft)", "Category", "Value", paramCategoryDataset, PlotOrientation.VERTICAL, true, true, false);
CategoryPlot localCategoryPlot = (CategoryPlot)localJFreeChart.getPlot();
localCategoryPlot.setForegroundAlpha(0.85F);
CategoryAxis localCategoryAxis = localCategoryPlot.getDomainAxis();
localCategoryAxis.setLowerMargin(0.0D);
localCategoryAxis.setUpperMargin(0.0D);
localCategoryAxis.setCategoryMargin(0.0D);
NumberAxis localNumberAxis = (NumberAxis)localCategoryPlot.getRangeAxis();
localNumberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
CategoryItemRenderer localCategoryItemRenderer = localCategoryPlot.getRenderer();
localCategoryItemRenderer.setBaseItemLabelsVisible(true);
return localJFreeChart;
}
public static JPanel createDemoPanel()
{
JFreeChart localJFreeChart = createChart(createDataset());
return new ChartPanel(localJFreeChart);
}
public static void main(String[] paramArrayOfString)
{
StackedAreaChartDemo1 localStackedAreaChartDemo1 = new StackedAreaChartDemo1("JFreeChart: StackedAreaChartDemo1.java (by Jou'Soft)");
localStackedAreaChartDemo1.pack();
RefineryUtilities.centerFrameOnScreen(localStackedAreaChartDemo1);
localStackedAreaChartDemo1.setVisible(true);
}
}
El resultado seria el siguiente:
Codigo Fuente:
package ejemplos;
import java.awt.Dimension;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class StackedAreaChartDemo1 extends ApplicationFrame
{
public StackedAreaChartDemo1(String paramString)
{
super(paramString);
JPanel localJPanel = createDemoPanel();
localJPanel.setPreferredSize(new Dimension(500, 270));
setContentPane(localJPanel);
}
public static CategoryDataset createDataset()
{
DefaultCategoryDataset localDefaultCategoryDataset = new DefaultCategoryDataset();
localDefaultCategoryDataset.addValue(1.0D, "S1", "C1");
localDefaultCategoryDataset.addValue(2.0D, "S1", "C2");
localDefaultCategoryDataset.addValue(3.0D, "S1", "C3");
localDefaultCategoryDataset.addValue(4.0D, "S1", "C4");
localDefaultCategoryDataset.addValue(5.0D, "S1", "C5");
localDefaultCategoryDataset.addValue(6.0D, "S1", "C6");
localDefaultCategoryDataset.addValue(7.0D, "S1", "C7");
localDefaultCategoryDataset.addValue(8.0D, "S1", "C8");
localDefaultCategoryDataset.addValue(6.0D, "S2", "C1");
localDefaultCategoryDataset.addValue(3.0D, "S2", "C2");
localDefaultCategoryDataset.addValue(4.0D, "S2", "C3");
localDefaultCategoryDataset.addValue(3.0D, "S2", "C4");
localDefaultCategoryDataset.addValue(9.0D, "S2", "C5");
localDefaultCategoryDataset.addValue(7.0D, "S2", "C6");
localDefaultCategoryDataset.addValue(2.0D, "S2", "C7");
localDefaultCategoryDataset.addValue(3.0D, "S2", "C8");
localDefaultCategoryDataset.addValue(1.0D, "S3", "C1");
localDefaultCategoryDataset.addValue(7.0D, "S3", "C2");
localDefaultCategoryDataset.addValue(6.0D, "S3", "C3");
localDefaultCategoryDataset.addValue(7.0D, "S3", "C4");
localDefaultCategoryDataset.addValue(4.0D, "S3", "C5");
localDefaultCategoryDataset.addValue(5.0D, "S3", "C6");
localDefaultCategoryDataset.addValue(3.0D, "S3", "C7");
localDefaultCategoryDataset.addValue(1.0D, "S3", "C8");
return localDefaultCategoryDataset;
}
public static JFreeChart createChart(CategoryDataset paramCategoryDataset)
{
JFreeChart localJFreeChart = ChartFactory.createStackedAreaChart("Stacked Area Chart by (Jou'Soft)", "Category", "Value", paramCategoryDataset, PlotOrientation.VERTICAL, true, true, false);
CategoryPlot localCategoryPlot = (CategoryPlot)localJFreeChart.getPlot();
localCategoryPlot.setForegroundAlpha(0.85F);
CategoryAxis localCategoryAxis = localCategoryPlot.getDomainAxis();
localCategoryAxis.setLowerMargin(0.0D);
localCategoryAxis.setUpperMargin(0.0D);
localCategoryAxis.setCategoryMargin(0.0D);
NumberAxis localNumberAxis = (NumberAxis)localCategoryPlot.getRangeAxis();
localNumberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
CategoryItemRenderer localCategoryItemRenderer = localCategoryPlot.getRenderer();
localCategoryItemRenderer.setBaseItemLabelsVisible(true);
return localJFreeChart;
}
public static JPanel createDemoPanel()
{
JFreeChart localJFreeChart = createChart(createDataset());
return new ChartPanel(localJFreeChart);
}
public static void main(String[] paramArrayOfString)
{
StackedAreaChartDemo1 localStackedAreaChartDemo1 = new StackedAreaChartDemo1("JFreeChart: StackedAreaChartDemo1.java (by Jou'Soft)");
localStackedAreaChartDemo1.pack();
RefineryUtilities.centerFrameOnScreen(localStackedAreaChartDemo1);
localStackedAreaChartDemo1.setVisible(true);
}
}
El resultado seria el siguiente:
Ejemplo jfreeChart: AreaChartDemo1
Bueno amigos, traigo una serie de codigos fuentes de varios ejemplos de la grandiosa herramienta jfreechart, la cual me he tomado la molestia de hacer los ejemplos de cada una de las graficas que existen, espero les sea de utilidad y cualquier duda me la hagan saber y me escriban a elnapster@gmail.com
AreaChartDemo1:
Codigo Fuente:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ejemplos;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RectangleEdge;
import org.jfree.ui.RectangleInsets;
import org.jfree.ui.RefineryUtilities;
import org.jfree.ui.VerticalAlignment;
import org.jfree.util.UnitType;
public class AreaChartDemo1 extends ApplicationFrame
{
public AreaChartDemo1(String paramString)
{
super(paramString);
JPanel localJPanel = createDemoPanel();
localJPanel.setPreferredSize(new Dimension(500, 270));
setContentPane(localJPanel);
}
private static CategoryDataset createDataset()
{
DefaultCategoryDataset localDefaultCategoryDataset = new DefaultCategoryDataset();
localDefaultCategoryDataset.addValue(1.0D, "Series 1", "Type 1");
localDefaultCategoryDataset.addValue(4.0D, "Series 1", "Type 2");
localDefaultCategoryDataset.addValue(3.0D, "Series 1", "Type 3");
localDefaultCategoryDataset.addValue(5.0D, "Series 1", "Type 4");
localDefaultCategoryDataset.addValue(5.0D, "Series 1", "Type 5");
localDefaultCategoryDataset.addValue(7.0D, "Series 1", "Type 6");
localDefaultCategoryDataset.addValue(7.0D, "Series 1", "Type 7");
localDefaultCategoryDataset.addValue(8.0D, "Series 1", "Type 8");
localDefaultCategoryDataset.addValue(5.0D, "Series 2", "Type 1");
localDefaultCategoryDataset.addValue(7.0D, "Series 2", "Type 2");
localDefaultCategoryDataset.addValue(6.0D, "Series 2", "Type 3");
localDefaultCategoryDataset.addValue(8.0D, "Series 2", "Type 4");
localDefaultCategoryDataset.addValue(4.0D, "Series 2", "Type 5");
localDefaultCategoryDataset.addValue(4.0D, "Series 2", "Type 6");
localDefaultCategoryDataset.addValue(2.0D, "Series 2", "Type 7");
localDefaultCategoryDataset.addValue(1.0D, "Series 2", "Type 8");
localDefaultCategoryDataset.addValue(4.0D, "Series 3", "Type 1");
localDefaultCategoryDataset.addValue(3.0D, "Series 3", "Type 2");
localDefaultCategoryDataset.addValue(2.0D, "Series 3", "Type 3");
localDefaultCategoryDataset.addValue(3.0D, "Series 3", "Type 4");
localDefaultCategoryDataset.addValue(6.0D, "Series 3", "Type 5");
localDefaultCategoryDataset.addValue(3.0D, "Series 3", "Type 6");
localDefaultCategoryDataset.addValue(4.0D, "Series 3", "Type 7");
localDefaultCategoryDataset.addValue(3.0D, "Series 3", "Type 8");
return localDefaultCategoryDataset;
}
private static JFreeChart createChart(CategoryDataset paramCategoryDataset)
{
JFreeChart localJFreeChart = ChartFactory.createAreaChart("Area Chart", "Category", "Value", paramCategoryDataset, PlotOrientation.VERTICAL, true, true, false);
localJFreeChart.setBackgroundPaint(Color.white);
TextTitle localTextTitle = new TextTitle("An area chart demonstration. We use this subtitle as an example of what happens when you get a really long title or subtitle.");
localTextTitle.setPosition(RectangleEdge.TOP);
localTextTitle.setPadding(new RectangleInsets(UnitType.RELATIVE, 0.05D, 0.05D, 0.05D, 0.05D));
localTextTitle.setVerticalAlignment(VerticalAlignment.BOTTOM);
localJFreeChart.addSubtitle(localTextTitle);
CategoryPlot localCategoryPlot = (CategoryPlot)localJFreeChart.getPlot();
localCategoryPlot.setForegroundAlpha(0.5F);
localCategoryPlot.setDomainGridlinesVisible(true);
CategoryAxis localCategoryAxis = localCategoryPlot.getDomainAxis();
localCategoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
localCategoryAxis.setLowerMargin(0.0D);
localCategoryAxis.setUpperMargin(0.0D);
localCategoryAxis.addCategoryLabelToolTip("Type 1", "The first type.");
localCategoryAxis.addCategoryLabelToolTip("Type 2", "The second type.");
localCategoryAxis.addCategoryLabelToolTip("Type 3", "The third type.");
NumberAxis localNumberAxis = (NumberAxis)localCategoryPlot.getRangeAxis();
localNumberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
localNumberAxis.setLabelAngle(0.0D);
ChartUtilities.applyCurrentTheme(localJFreeChart);
return localJFreeChart;
}
public static JPanel createDemoPanel()
{
JFreeChart localJFreeChart = createChart(createDataset());
return new ChartPanel(localJFreeChart);
}
public static void main(String[] paramArrayOfString)
{
AreaChartDemo1 localAreaChartDemo1 = new AreaChartDemo1("JFreeChart: AreaChartDemo1.java");
localAreaChartDemo1.pack();
RefineryUtilities.centerFrameOnScreen(localAreaChartDemo1);
localAreaChartDemo1.setVisible(true);
}
}
Como resultado final obtendremos:
AreaChartDemo1:
Codigo Fuente:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ejemplos;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RectangleEdge;
import org.jfree.ui.RectangleInsets;
import org.jfree.ui.RefineryUtilities;
import org.jfree.ui.VerticalAlignment;
import org.jfree.util.UnitType;
public class AreaChartDemo1 extends ApplicationFrame
{
public AreaChartDemo1(String paramString)
{
super(paramString);
JPanel localJPanel = createDemoPanel();
localJPanel.setPreferredSize(new Dimension(500, 270));
setContentPane(localJPanel);
}
private static CategoryDataset createDataset()
{
DefaultCategoryDataset localDefaultCategoryDataset = new DefaultCategoryDataset();
localDefaultCategoryDataset.addValue(1.0D, "Series 1", "Type 1");
localDefaultCategoryDataset.addValue(4.0D, "Series 1", "Type 2");
localDefaultCategoryDataset.addValue(3.0D, "Series 1", "Type 3");
localDefaultCategoryDataset.addValue(5.0D, "Series 1", "Type 4");
localDefaultCategoryDataset.addValue(5.0D, "Series 1", "Type 5");
localDefaultCategoryDataset.addValue(7.0D, "Series 1", "Type 6");
localDefaultCategoryDataset.addValue(7.0D, "Series 1", "Type 7");
localDefaultCategoryDataset.addValue(8.0D, "Series 1", "Type 8");
localDefaultCategoryDataset.addValue(5.0D, "Series 2", "Type 1");
localDefaultCategoryDataset.addValue(7.0D, "Series 2", "Type 2");
localDefaultCategoryDataset.addValue(6.0D, "Series 2", "Type 3");
localDefaultCategoryDataset.addValue(8.0D, "Series 2", "Type 4");
localDefaultCategoryDataset.addValue(4.0D, "Series 2", "Type 5");
localDefaultCategoryDataset.addValue(4.0D, "Series 2", "Type 6");
localDefaultCategoryDataset.addValue(2.0D, "Series 2", "Type 7");
localDefaultCategoryDataset.addValue(1.0D, "Series 2", "Type 8");
localDefaultCategoryDataset.addValue(4.0D, "Series 3", "Type 1");
localDefaultCategoryDataset.addValue(3.0D, "Series 3", "Type 2");
localDefaultCategoryDataset.addValue(2.0D, "Series 3", "Type 3");
localDefaultCategoryDataset.addValue(3.0D, "Series 3", "Type 4");
localDefaultCategoryDataset.addValue(6.0D, "Series 3", "Type 5");
localDefaultCategoryDataset.addValue(3.0D, "Series 3", "Type 6");
localDefaultCategoryDataset.addValue(4.0D, "Series 3", "Type 7");
localDefaultCategoryDataset.addValue(3.0D, "Series 3", "Type 8");
return localDefaultCategoryDataset;
}
private static JFreeChart createChart(CategoryDataset paramCategoryDataset)
{
JFreeChart localJFreeChart = ChartFactory.createAreaChart("Area Chart", "Category", "Value", paramCategoryDataset, PlotOrientation.VERTICAL, true, true, false);
localJFreeChart.setBackgroundPaint(Color.white);
TextTitle localTextTitle = new TextTitle("An area chart demonstration. We use this subtitle as an example of what happens when you get a really long title or subtitle.");
localTextTitle.setPosition(RectangleEdge.TOP);
localTextTitle.setPadding(new RectangleInsets(UnitType.RELATIVE, 0.05D, 0.05D, 0.05D, 0.05D));
localTextTitle.setVerticalAlignment(VerticalAlignment.BOTTOM);
localJFreeChart.addSubtitle(localTextTitle);
CategoryPlot localCategoryPlot = (CategoryPlot)localJFreeChart.getPlot();
localCategoryPlot.setForegroundAlpha(0.5F);
localCategoryPlot.setDomainGridlinesVisible(true);
CategoryAxis localCategoryAxis = localCategoryPlot.getDomainAxis();
localCategoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
localCategoryAxis.setLowerMargin(0.0D);
localCategoryAxis.setUpperMargin(0.0D);
localCategoryAxis.addCategoryLabelToolTip("Type 1", "The first type.");
localCategoryAxis.addCategoryLabelToolTip("Type 2", "The second type.");
localCategoryAxis.addCategoryLabelToolTip("Type 3", "The third type.");
NumberAxis localNumberAxis = (NumberAxis)localCategoryPlot.getRangeAxis();
localNumberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
localNumberAxis.setLabelAngle(0.0D);
ChartUtilities.applyCurrentTheme(localJFreeChart);
return localJFreeChart;
}
public static JPanel createDemoPanel()
{
JFreeChart localJFreeChart = createChart(createDataset());
return new ChartPanel(localJFreeChart);
}
public static void main(String[] paramArrayOfString)
{
AreaChartDemo1 localAreaChartDemo1 = new AreaChartDemo1("JFreeChart: AreaChartDemo1.java");
localAreaChartDemo1.pack();
RefineryUtilities.centerFrameOnScreen(localAreaChartDemo1);
localAreaChartDemo1.setVisible(true);
}
}
Como resultado final obtendremos:
Monday, April 12, 2010
Instalación de JFreeChart
.- REQUISITOS
- El paquete JFreeChart , el cual podremos descargar desde http://sourceforge.net/projects/jfreechart/ aunque el sitio oficial de JFreeChart es http://www.jfree.org/jfreechart/
- El paquete JCommon, se descarga de http://sourceforge.net/projects/jfreechart/files/3.%20JCommon/
- La documentación del JFreeChart (opcional) .
Es necesario descargar descargar el paquete JFreeChart ; opcionalmente se recomienda descargar también el paquete JCommon. Aunque una versión parcial del mismo ya viene incluido dentro de JFreeChart.
I- CONFIGURACIÓN DE EL JFREECHART Y EL JCOMMON
A continuación iniciaremos los pasos para poder configurar JFreeChart en la IDE NetBeans :
- Una vez que descargamos el paquete JFreeChart y el paquete JCommon lo descomprimimos en un directorio de la PC .
- Ahora abriremos el NetBeans para configurar las librerías de JFreeChart y JCommon , por lo tanto en NetBeans nos vamos al menú Tools y Seleccionamos Libraries :
- Hacemos clic en New Library y escribimos “JCommon-1.0.16” como nombre de la librería luego iremos a la pestaña Classpath → Add Jar/Folder y luego buscamos la dirección del JCommon descargado anteriormente y seleccionamos el archivo JCommon-1.0.16.jar :
- Hacemos lo mismo con el jar que descargamos del JfreeChart , OJo que el jar que seleccionamos en este caso es el de la carpeta lib .
- Hecho esto ya tenemos configurado las librerías de JFreechart y JCommon en el NetBeans ; hora ya podremos generar un gráfico .
Subscribe to:
Posts (Atom)