最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

java類中生成jfreechart,返回圖表的url地址 代碼分享

 更新時(shí)間:2013年08月22日 14:57:30   作者:  
這篇文章介紹了java類中生成jfreechart,返回圖表的url地址的代碼,有需要的朋友可以參考一下

web.xml中設(shè)置:

復(fù)制代碼 代碼如下:

<servlet>
<servlet-name>DisplayChart</servlet-name>
<servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-class>
</servlet >
<servlet-mapping>
<servlet-name>DisplayChart</servlet-name>
<url-pattern>/DisplayChart</url-pattern>
</servlet-mapping>

java類中方法:
復(fù)制代碼 代碼如下:

public String getChart(String series[],double score[][],String type[],String name){
final int num=8;
DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
for(int i=0;i<type.length;i++){ 
type[i]=type[i].substring(0, (type[i].length()<num)?type[i].length():num);
}

for(int j=0;j<series.length;j++){
int i=0;
for( i=0;i<type.length;i++){
defaultcategorydataset.addValue(score[j][i], series[j], type[i]); 
}
}

JFreeChart jfreechart = ChartFactory.createLineChart(name,null,null,defaultcategorydataset,PlotOrientation.VERTICAL,true,true,false);

jfreechart.getLegend().setPosition(RectangleEdge.RIGHT);

jfreechart.setBackgroundPaint(Color.white);

CategoryPlot categoryplot = (CategoryPlot)jfreechart.getPlot();
categoryplot.setNoDataMessage("無數(shù)據(jù)可供顯示!");
categoryplot.setBackgroundPaint(Color.white);
categoryplot.setDomainGridlinesVisible(true);
categoryplot.setRangeGridlinesVisible(true);
categoryplot.setRangeGridlinePaint(Color.gray);
categoryplot.setDomainGridlinePaint(Color.gray);
categoryplot.setBackgroundAlpha(0.8f);
Font font1 = new Font("黑體",Font.BOLD, 14);
jfreechart.getTitle().setFont(font1);

Font font3 = new Font("隸書",Font.BOLD, 12);
jfreechart.getLegend().setItemFont(font3);

CategoryAxis categoryaxis = categoryplot.getDomainAxis();
//  categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
categoryaxis.setMaximumCategoryLabelLines(10);//行數(shù),根據(jù)需要自己設(shè)
categoryaxis.setMaximumCategoryLabelWidthRatio(0.5f);//每行寬度,這里設(shè)一個(gè)漢字寬

NumberAxis numberaxis = (NumberAxis)categoryplot.getRangeAxis();
numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
numberaxis.setAutoRangeIncludesZero(true);
numberaxis.setRangeWithMargins(0, 3);

numberaxis.setUpperMargin(0.8);////設(shè)置最高的一個(gè) Item 與圖片頂端的距離
numberaxis.setUpperBound(3.5);//縱坐標(biāo)最大值

categoryaxis.setTickLabelFont(new Font("宋體", Font.BOLD, 12));
numberaxis.setTickLabelFont(new Font("隸書", Font.BOLD, 12));
Font font2 = new Font("SimSun", Font.BOLD, 16);
categoryaxis.setLabelFont(font2);
numberaxis.setLabelFont(font2);
categoryplot.setAxisOffset(new RectangleInsets(0D, 0D,0D, 10D));//設(shè)置曲線圖與xy軸的距離
LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer)categoryplot.getRenderer();
lineandshaperenderer.setShapesVisible(true); //數(shù)據(jù)點(diǎn)可見

lineandshaperenderer.setSeriesStroke(0, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] {
10F, 6F
}, 0.0F)); //定義series點(diǎn)之間的連線 ,這里是虛線,默認(rèn)是直線
lineandshaperenderer.setSeriesStroke(1, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] {
6F, 6F
}, 0.0F));

lineandshaperenderer.setBaseItemLabelsVisible(true);
lineandshaperenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());

ChartRenderingInfo info=new ChartRenderingInfo(new StandardEntityCollection());
String fileName = null;
try
{
fileName = ServletUtilities.saveChartAsPNG(jfreechart, 700,300, info, null);//生成圖片
}
catch (IOException e)
{
e.printStackTrace();
}

String graphURL = "/projectname/DisplayChart?filename=" + fileName; //projectname為對(duì)應(yīng)項(xiàng)目的路徑path,一般就是項(xiàng)目名稱

//jsp中這樣使用: String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
return graphURL;//返回生成圖片的地址
}


調(diào)用上述方法得到生成的chart的url:
復(fù)制代碼 代碼如下:

   getChart(stus,score_field,type,"總分圖");

相關(guān)文章

  • springboot實(shí)現(xiàn)用戶名查找用戶功能

    springboot實(shí)現(xiàn)用戶名查找用戶功能

    本文主要介紹了springboot實(shí)現(xiàn)用戶名查找用戶功能,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-04-04
  • ActiveMQ消息簽收機(jī)制代碼實(shí)例詳解

    ActiveMQ消息簽收機(jī)制代碼實(shí)例詳解

    這篇文章主要介紹了ActiveMQ消息簽收機(jī)制代碼實(shí)例解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-02-02
  • SpringBoot框架如何操作Excel和PDF

    SpringBoot框架如何操作Excel和PDF

    Excel和PDF都是常見的辦公文件類型,在實(shí)際需求中有著較多的應(yīng)用,excel經(jīng)常用來處理數(shù)據(jù),PDF文件格式可以將文字、字型、格式、顏色及獨(dú)立于設(shè)備和分辨率的圖形圖像等封裝在一個(gè)文件中,本文就講述下SpringBoot框架如何操作這兩種類型的文件
    2021-06-06
  • 在java中由類名和方法名字符串實(shí)現(xiàn)其調(diào)用方式

    在java中由類名和方法名字符串實(shí)現(xiàn)其調(diào)用方式

    這篇文章主要介紹了在java中由類名和方法名字符串實(shí)現(xiàn)其調(diào)用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • spring boot 1.5.4 集成shiro+cas,實(shí)現(xiàn)單點(diǎn)登錄和權(quán)限控制

    spring boot 1.5.4 集成shiro+cas,實(shí)現(xiàn)單點(diǎn)登錄和權(quán)限控制

    這篇文章主要介紹了spring boot 1.5.4 集成shiro+cas,實(shí)現(xiàn)單點(diǎn)登錄和權(quán)限控制,需要的朋友可以參考下
    2017-06-06
  • java生成抽樣隨機(jī)數(shù)的多種算法

    java生成抽樣隨機(jī)數(shù)的多種算法

    本文主要介紹了java生成抽樣隨機(jī)數(shù)的多種算法,主要是基于random庫函數(shù)的,有需要的可以了解一下。
    2016-10-10
  • Trie樹(字典樹)的介紹及Java實(shí)現(xiàn)

    Trie樹(字典樹)的介紹及Java實(shí)現(xiàn)

    Trie樹,又稱字典樹或前綴樹,關(guān)于它的結(jié)構(gòu)就不詳細(xì)介紹了。Trie樹在單詞統(tǒng)計(jì)、前綴匹配等很多方面有很大用處。下面這篇文章主要介紹了Trie樹,以及Java實(shí)現(xiàn)如何Trie樹,有需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-02-02
  • Mybatis使用Collection屬性的示例代碼

    Mybatis使用Collection屬性的示例代碼

    本文主要介紹了Mybatis使用Collection屬性的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-07-07
  • 全面解析JTA 深度歷險(xiǎn)

    全面解析JTA 深度歷險(xiǎn)

    本文介紹了利用 JTA 深度歷險(xiǎn)的相關(guān)內(nèi)容,充分舉例說明JTA的原理和事務(wù)處理等相關(guān)內(nèi)容,十分詳細(xì),需要的朋友可以參考下。
    2017-09-09
  • SpringBoot緩存Ehcache的使用詳解

    SpringBoot緩存Ehcache的使用詳解

    EhCache、Redis比較常用,使用Redis的時(shí)候需要先安裝Redis服務(wù)器,本文給大家介紹SpringBoot緩存Ehcache的使用詳解,感興趣的朋友跟隨小編一起看看吧
    2022-03-03

最新評(píng)論

德州市| 南乐县| 萝北县| 柯坪县| 西畴县| 扎囊县| 东兴市| 浏阳市| 克什克腾旗| 罗定市| 平潭县| 中宁县| 固安县| 玛纳斯县| 波密县| 广平县| 贵州省| 樟树市| 灵丘县| 搜索| 沅陵县| 郴州市| 绩溪县| 潍坊市| 哈尔滨市| 东山县| 西吉县| 旌德县| 彝良县| 广饶县| 台南县| 海宁市| 梅河口市| 革吉县| 遵义市| 镇赉县| 杂多县| 含山县| 项城市| 金塔县| 读书|