KChart PDF Print E-mail
Written by Administrator   
Friday, 16 April 2010 19:35

KChart is a wrapper library for JFreeChart. It provides simplified interface similat to Matlab's interface. It does not cover all JFreeChart functionality, but enables us to do simple things in a simple way.

 

 

License: LGPL 2.1, contact me for commercial license at gmail, user markok3.14

Usage

Download jar file and add it your classpath. Then you can use provided classes.

Downloads

KChart-1.0.2.jar

KChart-1.0.2-src.zip

KChart-1.0.2-doc.zip

KChart-1.0.2-bin.zip - contains KChart jar file, required jars (JFreeChart), and documentation

Examples

Below you can find the most interesting pieces of code and resulting images from demo application, which is part of source distribution.

Lines with markers

Code

KChart chart = new KChart();
chart.setTitle("test1");
final int NUM_PTS = 50;
double x[] = new double[NUM_PTS];
double y1[] = new double[NUM_PTS];
double y2[] = new double[NUM_PTS];
double y3[] = new double[NUM_PTS];
double y4[] = new double[NUM_PTS];
double y5[] = new double[NUM_PTS];
double y6[] = new double[NUM_PTS];
double y7[] = new double[NUM_PTS];
double y8[] = new double[NUM_PTS];
double y9[] = new double[NUM_PTS];
double y10[] = new double[NUM_PTS];
double y11[] = new double[NUM_PTS];
for (int i = 0; i < NUM_PTS; i++) {
x[i] = i;
y1[i] = Math.sin(6. * i / NUM_PTS * Math.PI)*2;
y2[i] = Math.sin(6. * i / NUM_PTS * Math.PI)*3;
y3[i] = Math.sin(6. * i / NUM_PTS * Math.PI)*4;
y4[i] = Math.sin(6. * i / NUM_PTS * Math.PI)*5;
y5[i] = Math.sin(6. * i / NUM_PTS * Math.PI)*6;
y6[i] = Math.sin(6. * i / NUM_PTS * Math.PI)*7;
y7[i] = Math.sin(6. * i / NUM_PTS * Math.PI)*8;
y8[i] = Math.sin(6. * i / NUM_PTS * Math.PI)*9;
y9[i] = Math.sin(6. * i / NUM_PTS * Math.PI)*10;
y10[i] = Math.sin(6. * i / NUM_PTS * Math.PI)*11;
y11[i] = Math.sin(6. * i / NUM_PTS * Math.PI)*12;
}
chart.plot(x, y1, "k-+", "sin1",
x, y2, "k-*", "sin2",
x, y3, "k-^", "sin3",
x, y4, "k-v", "sin4",
x, y5, "k-<", "sin5",
x, y6, "k->", "sin6",
x, y7, "k-o", "sin7",
x, y8, "k-x", "sin8",
x, y9, "k-s", "sin9",
x, y10, "k-d", "sin10",
x, y11, "k.-", "sin11");

chart.setLineVisibility(KChart.LAST_IDX, true, true);
chart.showInNewFrame();

Result

 

Colored lines

Code

final int NUM_PTS = 10;
double[] x = new double[NUM_PTS];
double[] y1 = new double[NUM_PTS];
double[] y2 = new double[NUM_PTS];
double[] y3 = new double[NUM_PTS];
double[] y4 = new double[NUM_PTS];
double[] y5 = new double[NUM_PTS];
double[] y6 = new double[NUM_PTS];

for (int i = 0; i < NUM_PTS; i++) {
x[i] = i;
y1[i] = Math.log(i + 1);
y2[i] = Math.log(i*10 + 10);
y3[i] = Math.log(i*100 + 100);
y4[i] = Math.log(i*1000 + 1000);
y5[i] = Math.log(i*10000 + 10000);
y6[i] = Math.log(i*100000 + 100000);
}
KChart chart = new KChart("test3");
chart.plot(x, y1, x, y2, x, y3, x, y4, x, y5, x, y6);

chart.setLineSpec(0, "-", 1);
chart.setLineSpec(1, "--", 1);
chart.setLineSpec(2, "-.", 1);
chart.setLineSpec(3, ":", 1);
chart.setLineSpec(4, "x-", 3);
chart.setLineSpec(5, "d--r", 2);
chart.showInNewFrame();

Result

Colored lines of different thickness

Code

final int NUM_PTS = 10;
double[] x = new double[NUM_PTS];
double[] y1 = new double[NUM_PTS];
double[] y2 = new double[NUM_PTS];
double[] y3 = new double[NUM_PTS];
double[] y4 = new double[NUM_PTS];
double[] y5 = new double[NUM_PTS];
double[] y6 = new double[NUM_PTS];

for (int i = 0; i < NUM_PTS; i++) {
x[i] = i;
y1[i] = Math.exp(i + 1);
y2[i] = Math.exp(i + 2);
y3[i] = Math.exp(i + 3);
y4[i] = Math.exp(i + 4 );
y5[i] = Math.exp(i + 5);
y6[i] = Math.exp(i + 6);
}
KChart chart = new KChart("test4");
String[] ids = chart.plot(x, y1, x, y2);
chart.setLineColor(ids[0], Color.blue);
chart.setLineStyle(ids[0], new Rectangle2D.Double(-5, -5, 10, 10), 3);

String thirdLineId = chart.addPlot(x, y3, "r:", "thirdLine");
chart.setLineSpec(thirdLineId, "g-d", 5);
chart.showInNewFrame();

Result

 

Last Updated on Saturday, 17 April 2010 19:40
 

Add comment


Security code
Refresh