如何使用java做统计图表

如何使用java做统计图表,第1张

//参考地址http://echarts.baidu.com/去网站下js控件,下面是饼图的代码,下图是我的代码效果

function query1(housetype,redStatisticsList,text0,cashingSum,tranferSum){

<!--红包发放数据-->

var myrodiusred = echarts.init(document.getElementById('mainrodius'))//ID

var redHousehold = housetype

var redMoney = redStatisticsList

var allMoney = 0//总金额

$.each(redStatisticsList,function(index,item){

allMoney =allMoney+ Number(item.value)

})

optionTwo = {

title : {

text: text0,

subtext: "总金额:"+allMoney+"\n\n提现总额:"+cashingSum+"\n\n到账总额:"+tranferSum,

x:'center'

},

tooltip : {

trigger: 'item',

formatter: "{a} <br/>{b} ({d}%)"

},

legend: {

orient: 'vertical',

left: 'left',

data: housetype

},

series : [

{

type: 'pie',

radius : '55%',

center: ['50%', '60%'],

data:redMoney,

itemStyle: {

emphasis: {

shadowBlur: 10,

shadowOffsetX: 0,

shadowColor: 'rgba(0, 0, 0, 0.5)'

}

}

}

]

}

        myrodiusred.setOption(optionTwo)

      }

用jfreechart

jfreechart绘制柱状图

import java.io.File

import java.io.IOException

import org.jfree.chart.ChartFactory

import org.jfree.chart.ChartUtilities

import org.jfree.chart.JFreeChart

import org.jfree.chart.plot.PlotOrientation

import org.jfree.data.category.DefaultCategoryDataset

/*

* 绘制柱状图

*你亮哥

* */

public class BarChart3DDemo

{

public static void main(String[] args)

{

try

{

//设置主题

ChartFactory.setChartTheme(Theme.getTheme())

//构造数据

DefaultCategoryDataset dataset = new DefaultCategoryDataset()

dataset.addValue(100, "JAVA","1")

dataset.addValue(200, "js","1")

dataset.addValue(200, "C++", "2")

dataset.addValue(300, "C", "3")

dataset.addValue(400, "HTML", "4")

dataset.addValue(400, "CSS", "5")

/*

* public static JFreeChart createBarChart3D(

* java.lang.String title, 设置图表的标题

* java.lang.String categoryAxisLabel, 设置分类轴的标示

* java.lang.String valueAxisLabel, 设置值轴的标示

* CategoryDataset dataset, 设置数据

* PlotOrientation orientation, 设置图表的方向

* boolean legend, 设置是否显示图例

* boolean tooltips,设置是否生成热点工具

* boolean urls) 设置是否显示url

*/

JFreeChart chart = ChartFactory.createBarChart3D("编程语言统计", "语言",

"学习人数", dataset, PlotOrientation.VERTICAL, true, false,

false)

//保存图表

ChartUtilities.saveChartAsPNG(new File("E:/chart/BarChart3D.png"), chart, 800, 500)

System.out.println("绘图完成")

}

catch (IOException e)

{

e.printStackTrace()

}

}

}

===================================================================================

//一条线 有点 有数

package Test

import java.awt.Color

import java.awt.Font

import org.jfree.chart.ChartFactory

import org.jfree.chart.ChartFrame

import org.jfree.chart.JFreeChart

import org.jfree.chart.axis.AxisSpace

import org.jfree.chart.labels.ItemLabelAnchor

import org.jfree.chart.labels.ItemLabelPosition

import org.jfree.chart.labels.StandardXYItemLabelGenerator

import org.jfree.chart.plot.XYPlot

import org.jfree.chart.renderer.xy.XYItemRenderer

import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer

import org.jfree.chart.title.TextTitle

import org.jfree.data.time.Month

import org.jfree.data.time.TimeSeries

import org.jfree.data.time.TimeSeriesCollection

import org.jfree.ui.RectangleInsets

import org.jfree.ui.TextAnchor

public class try123 {

public static void main(String[] args){

//首先构造数据

TimeSeries timeSeries = new TimeSeries("BMI", Month.class)

// 时间曲线数据集合

TimeSeriesCollection lineDataset = new TimeSeriesCollection()

// 构造数据集合

timeSeries.add(new Month(1, 2009), 45)

timeSeries.add(new Month(2, 2009), 46)

timeSeries.add(new Month(3, 2009), 1)

timeSeries.add(new Month(4, 2009), 500)

timeSeries.add(new Month(5, 2009), 43)

timeSeries.add(new Month(6, 2009), 324)

timeSeries.add(new Month(7, 2009), 632)

timeSeries.add(new Month(8, 2009), 34)

timeSeries.add(new Month(9, 2009), 12)

timeSeries.add(new Month(10, 2009), 543)

timeSeries.add(new Month(11, 2009), 32)

timeSeries.add(new Month(12, 2009), 225)

lineDataset.addSeries(timeSeries)

JFreeChart chart = ChartFactory.createTimeSeriesChart("", "date", "bmi", lineDataset, true, true, true)

//增加标题

chart.setTitle(new TextTitle("XXXBMI指数", new Font("隶书", Font.ITALIC, 15)))

chart.setAntiAlias(true)

XYPlot plot = (XYPlot) chart.getPlot()

plot.setAxisOffset(new RectangleInsets(10,10,10,10))//图片区与坐标轴的距离

plot.setOutlinePaint(Color.PINK)

plot.setInsets(new RectangleInsets(15,15,15,15))//坐标轴与最外延的距离

// plot.setOrientation(PlotOrientation.HORIZONTAL)//图形的方向,包括坐标轴。

AxisSpace as = new AxisSpace()

as.setLeft(25)

as.setRight(25)

plot.setFixedRangeAxisSpace(as)

chart.setPadding(new RectangleInsets(5,5,5,5))

chart.setNotify(true)

// 设置曲线是否显示数据点

XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)plot.getRenderer()

xylineandshaperenderer.setBaseShapesVisible(true)

// 设置曲线显示各数据点的值

XYItemRenderer xyitem = plot.getRenderer()

xyitem.setBaseItemLabelsVisible(true)

xyitem.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE10, TextAnchor.BASELINE_LEFT))

xyitem.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator())

xyitem.setBaseItemLabelFont(new Font("Dialog", 1, 14))

plot.setRenderer(xyitem)

//显示

ChartFrame frame = new ChartFrame("try1", chart)

frame.pack()

frame.setVisible(true)

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12064063.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存