The project also needs to use jfreechart to generate a dashboard, and quickly found the code on the internet, used it to modify it, and finally output the image to the local device. the project needs are changing, and everything is possible.
Import java. AWT. basicstroke;
Import java. AWT. color;
Import java. AWT. dimension;
Import java. AWT. Font;
Import java. Io. file;
Import javax. Swing. jpanel;
Import org. jfree. Chart. chartpanel;
Import org. jfree. Chart. chartutilities;
Import org. jfree. Chart. jfreechart;
Import org. jfree. Chart. Plot. dialshape;
Import org. jfree. Chart. Plot. meterinterval;
Import org. jfree. Chart. Plot. meterplot;
Import org. jfree. Data. range;
Import org. jfree. Data. General. defaultvaluedataset;
Import org. jfree. Data. General. valuedataset;
Import org. jfree. UI. applicationframe;
Import org. jfree. UI. refineryutilities;
Public class meterchartdemo1 extends applicationframe ...{
Public meterchartdemo1 (string s )...{
Super (s );
Jpanel = createdemopanel ();
Jpanel. setpreferredsize (new dimension (500,270 ));
Setcontentpane (jpanel );
}
// Create a gauge chart
Private Static jfreechart createchart (valuedataset )...{
Meterplot = new meterplot (valuedataset );
Meterplot. setrange (new range (0.0d, 60d ));
Meterplot. addinterval (New meterinterval ("normal ",
New range (0.0d, 35d), color. lightgray, new basicstroke (2.0f ),
New Color (0,255, 0, 64 )));
Meterplot. addinterval (New meterinterval ("warning ",
New range (35d, 50d), color. lightgray, new basicstroke (2.0f ),
New Color (255,255, 0, 64 )));
Meterplot. addinterval (New meterinterval ("critical", new range (50d,
60d), color. lightgray, new basicstroke (2.0f), new color (255, 0,
0,128 )));
Meterplot. setneedlepaint (color. darkgray );
Meterplot. setdialbackgroundpaint (color. White );
Meterplot. setdialoutlinepaint (color. Gray );
Meterplot. setdialshape (dialshape. chord );
Meterplot. setmeterangle (260 );
Meterplot. setticklabelsvisible (true );
Meterplot. setticklabelfont (new font ("dialog", 1, 10 ));
Meterplot. setticklabelpaint (color. darkgray );
Meterplot. setticksize (5D );
Meterplot. settickpaint (color. lightgray );
Meterplot. setvaluepaint (color. Black );
Meterplot. setvaluefont (new font ("dialog", 1, 14 ));
Jfreechart = new jfreechart ("meter Chart 1 ",
Jfreechart. default_title_font, meterplot, true );
Return jfreechart;
}
// Graphic display for debugging and calling of the Output Method
Public static jpanel createdemopanel ()...{
Dataset = new defaultvaluedataset (23D );
Jfreechart = createchart (Dataset );
Outputjpg (jfreechart );
Chartpanel = new chartpanel (jfreechart );
Return chartpanel;
}
Public static void main (string ARGs [])... {
Meterchartdemo1 meterchartdemo1 = new meterchartdemo1 (
"Meter chart demo 1 ");
Meterchartdemo1.pack ();
Refineryutilities. centerframeonscreen (meterchartdemo1 );
Meterchartdemo1.setvisible (true );
}
// Output the image to the local directory
Public static void outputjpg (jfreechart chart )...{
Try ...{
File fp = new file ("C:/test.jpg ");
Chartutilities. savechartasjpeg (FP, charts, 300,300 );
} Catch (exception e )...{
}
}
Private Static defaultvaluedataset dataset;
}