Dashboard Home

Create Line Chart | jfree | dashboard

Create Line Chart | jfree | dashboard

The basic requirement for a line chart is same as the bar chart. You need minimum of two columns, if you add more than two columns then it adds another line in the same chart corresponding to the numeric column

 

select job_type,

max_salary as VAL ,

min_salary as SVAL

from job_table

 

The first column forms the X- Axis, the columns VAL and SVAL make the corresponding red and blue line

 

When you first create the chart it appears as below

 

You can change the line appearance as below by turning javascript on

 

//import the necessary classes

import org.jfree.*;

import org.jfree.chart.axis.CategoryAxis;

//import org.jfree.chart.axis.CategoryLabelPositions;

import org.jfree.chart.axis.NumberAxis;

//import org.jfree.chart.labels.CategoryItemLabelGenerator;

//import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;

import org.jfree.chart.plot.CategoryPlot;

import org.jfree.chart.renderer.category.LineAndShapeRenderer;  

//       CategoryPlot plot= chart.getCategoryPlot();

          LineAndShapeRenderer lrenderer       = (LineAndShapeRenderer) plot.getRenderer();

          lrenderer.setStroke(

          new BasicStroke(4f, BasicStroke.JOIN_ROUND, BasicStroke.JOIN_BEVEL)

          );

      float h = displayFrame.getHeight();

      float w = displayFrame.getWidth();

                  // GradientPaint gradientPaint = new GradientPaint(0.0F, 10.0F, Color.WHITE, h, w, Color.green.darker());

                    //plot.setBackgroundPaint(gradientPaint);

                    chart.setBackgroundPaint(new GradientPaint(0,0,Color.white,w,h, new Color(235,235,205)));