Javaxychart的简单介绍

博主:adminadmin 2022-12-05 15:12:10 73

今天给各位分享Javaxychart的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

怎么用java做柱形图!!!

首先要有jfreechart.jar和jcommon-1.0.12.jar两个包然后在web.xml配置

servlet

servlet-nameDisplayChart/servlet-name

servlet-classorg.jfree.chart.servlet.DisplayChart/servlet-class

/servlet

servlet-mapping

servlet-nameDisplayChart/servlet-name

url-pattern/DisplayChart/url-pattern

/servlet-mapping

最后是jsp代码:

%@ page contentType="text/html;charset=GBK"%

%@ page import="org.jfree.chart.ChartFactory,

org.jfree.chart.JFreeChart,

org.jfree.chart.plot.PlotOrientation,

org.jfree.chart.servlet.ServletUtilities,

org.jfree.data.category.CategoryDataset,

org.jfree.data.general.DatasetUtilities"%

%

double[][] data = new double[][] {{1310}, {720}, {1130}, {440}};

String[] rowKeys = {"猪肉", "牛肉","鸡肉", "鱼肉"};

String[] columnKeys = {""};

CategoryDataset dataset = DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data);

JFreeChart chart = ChartFactory.createBarChart3D("广州肉类销量统计图", "肉类",

"销量",

dataset,

PlotOrientation.VERTICAL,

true,

false,

false);

String filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, null, session);

String graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename;

%

img src="%= graphURL %"width=500 height=300 border=0 usemap="#%= filename %"

如何在java中使用chart动态设置图表大小??

  ListPointValue valuesLow = new ArrayListPointValue();//每天的最低温度

ListPointValue valuesHigh = new ArrayListPointValue(); //每天的最高温度

for(int i=0;ilist.size();i++){//list为数据集合 数据结构如下:

/** "future":[

{

"date":"2016-03-25",

"dayTime":"晴",

"night":"晴",

"temperature":"15°C / 3°C",

"week":"今天",

"wind":"无持续风向 小于3级"

},

] */

String[] temp=list.get(i).getTemperature().split("/",2);

//x轴座标其实就是从i开始到需要的那天结束 此次截取字符串。。

valuesHihg.add(new PointValue(i,Integer.parseInt(temp[0].trim().substring(0,temp[0].length()-3).trim())).setLabel(temp[0]));

if (temp[1].length()==0||temp[1]==null||temp.length==1)

temp[1] = "0000";

valuesLow.add(new PointValue(i,Integer.parseInt(temp[1].trim().substring(0,temp[1].length()-3).trim())).setLabel(temp[1]));

}

initLineChart(valuesHigh,valuesLow);//处理图表

下面就是对图表各属性的设置了

/**

* 初始化LineChart的一些设置

*/

private void initLineChart(ListPointValue highPointValues,ListPointValue lowPointValues){

ListLine lines = new ArrayListLine();

Line line = new Line(highPointValues).setColor(Color.parseColor("#C0D79C")).setStrokeWidth(1); //折线的颜色、粗细

line.setShape(ValueShape.CIRCLE);//折线图上每个数据点的形状 这里是圆形 (有三种 :ValueShape.SQUARE ValueShape.CIRCLE ValueShape.SQUARE)

line.setCubic(true);//曲线是否平滑

line.setFilled(false);//是否填充曲线的面积

  line.setHasLabels(true);//曲线的数据坐标是否加上备注

line.setPointRadius(3); //座标点大小

line.setHasLabelsOnlyForSelected(false);//点击数据坐标提示数据(设置了这个line.setHasLabels(true);就无效)

line.setHasLines(true);//是否用直线显示。如果为false 则没有曲线只有点显示

line.setHasPoints(true);//是否显示圆点 如果为false 则没有原点只有点显示

lines.add(line);

Line lineLow = new Line(lowPointValues).setColor(Color.parseColor("#C0D79C")).setStrokeWidth(1);

lineLow.setShape(ValueShape.CIRCLE);//折线图上每个数据点的形状 这里是圆形 (有三种 :ValueShape.SQUARE ValueShape.CIRCLE ValueShape.SQUARE)

lineLow.setCubic(true);//曲线是否平滑

lineLow.setFilled(false);//是否填充曲线的面积

lineLow.setHasLabels(true);//曲线的数据坐标是否加上备注

lineLow.setPointRadius(3);

lineLow.setHasLabelsOnlyForSelected(false);//点击数据坐标提示数据(设置了这个line.setHasLabels(true);就无效)

lineLow.setHasLines(true);//是否用直线显示。如果为false 则没有曲线只有点显示

lineLow.setHasPoints(true);//是否显示圆点 如果为false 则没有原点只有点显示

lines.add(lineLow);

LineChartData data = new LineChartData();

data.setValueLabelBackgroundColor(Color.TRANSPARENT);//此处设置坐标点旁边的文字背景

data.setValueLabelBackgroundEnabled(false);

data.setValueLabelsTextColor(Color.BLACK); //此处设置坐标点旁边的文字颜色 data.setLines(lines);

//设置行为属性,支持缩放、滑动以及平移

mWeatherChart.setInteractive(false);

// mWeatherChart.setZoomType(ZoomType.HORIZONTAL_AND_VERTICAL);

// mWeatherChart.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);

mWeatherChart.setScrollEnabled(false);

mWeatherChart.setLineChartData(data);

mWeatherChart.setValueTouchEnabled(false);

mWeatherChart.setFocusableInTouchMode(false);

mWeatherChart.setVisibility(View.VISIBLE);

mWeatherChart.startDataAnimation();

}

java中用chart怎么在饼图上显示图例

你好你可以去网上搜的啊,你是用jfreechart吧,有文档的,但是官方的要收费

java 柱状图系统配置与实例

ChartDirector除了一个英文件的帮助以外,也没有再提供Java DOC形式的文档,为了方便,写以下一个例子说明使用ChartDirector生成柱状图的方法.jsp方式实质与JAVA方式没有区别,这里是我从JSP中取的代码(JSP改起来方便,不过手动)

代码如下:

%@ page language="java" contentType="text/Html; charset=UTF-8"

pageEncoding="UTF-8" import="ChartDirector.*;"%

%

request.setCharacterEncoding("UTF-8");

//以两个系列数据为例

double[] data = {185, 156, 179.5, 211, 123};

double[] data1 = {55, 76, 34.5, 88, 43};

//数据列名

String[] labels = {"一月", "二月", "三月", "四月", "五月"};

//生成图片大小 250 x 250

XYChart c = new XYChart(550, 350);

//图标题

c.addTitle("第一个图","",15);

//支持中文

c.setDefaultFonts("SIMSUN.TTC","simhei.ttf");

//图表在图片中的定位及区域大小

c.setPlotArea(30, 40, 400, 250);

//=========================

//加入单个数据

//BarLayer layer = c.addBarLayer(data,0xff3456,"我的测试");

//=========================

//加入多个BAR数据(多个datasets)

BarLayer layer = c.addBarLayer2(Chart.Side, 3);

layer.addDataSet(data, 0xff8080, "我测试1");

layer.addDataSet(data1, 0x008080, "你也测2");

//3d化

layer.set3D();

//设置BAR边框形式

layer.setBarShape(0);

//bar宽度

layer.setBarWidth(50);

//设置BAR边框颜色

//layer.setBorderColor(0xff9999);

//图例形式

layer.setLegend(1);

//每个BAR顶部加入数据显示

layer.setAggregateLabelStyle();

//设置BAR底部的名称显示

TextBox t = c.xAxis().setLabels(labels);

//名称文字大小

t.setFontSize(9);

//加图例

//LegendBox legend = c.addLegend(260, 120,true);

//legend.addKey("钱财",0xff8080);

//图例位置

c.addLegend(450, 120,true);

//output the chart

String chart1URL = c.makeSession(request, "chart1");

//include tool tip for the chart

String imageMap1 = c.getHTMLImageMap("#", "", "title='{xLabel}: US${value}K'");

%!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

html

head

meta http-equiv="Content-Type" content="text/html; charset=UTF-8"

title图表测试/title

/head

body

h1中文/h1

hr color="#000080"

br

img src='%=response.encodeURL("getchart.jsp?"+chart1URL)%'

usemap="#map1" border="0"

map name="map1"%=imageMap1%/map

/body

/html

资料引用:

JAVA WEB 项目发布到服务器,jfreechart不显示

您好,您这样:

%@ page contentType="text/html;charset=gb2312" pageEncoding="GB2312"%

%@ page import="com.bm.process.TimeSeriesChart"%

%@ page import = "java.io.PrintWriter" %

%

TimeSeriesChart xyChart=new TimeSeriesChart();

String fineName = xyChart.CreateTimeSeriesChart(); ------目前这些修改为返回文件的绝对路径 如 D:\temp\jfreechart-56814.png

%

body

img src="%= fineName %"

/body

/html

java JFreeChart 问题,X轴显示的是时间,但是数据太多,挤成一团,如何让X轴只显示10个时间

调整前(默认1年单位)

调整后(5年单位)

取得XYPlot,然后在DomainAxis里可以设置刻度。

(找了1小时。。。求采纳,没有功劳也有苦劳啊)

下面的代码是5年单位显示。

import java.io.File;

import java.io.IOException;

import java.text.SimpleDateFormat;

import org.jfree.chart.ChartFactory;

import org.jfree.chart.ChartUtilities;

import org.jfree.chart.JFreeChart;

import org.jfree.chart.axis.DateAxis;

import org.jfree.chart.axis.DateTickUnit;

import org.jfree.chart.plot.XYPlot;

import org.jfree.data.time.Month;

import org.jfree.data.time.TimeSeries;

import org.jfree.data.time.TimeSeriesCollection;

public class TimeSeriesChartSample {

    public static void main(String[] args) throws IOException {

        // Create Data

        TimeSeries s1 = new TimeSeries("XXXX");

        for (int i = 0; i  10; i++) {

            int year = 2000 + i;

            s1.add(new Month(1, year), 101.8);

            s1.add(new Month(2, year), 104.8);

            s1.add(new Month(3, year), 103.3);

            s1.add(new Month(4, year), 105.8);

            s1.add(new Month(5, year), 110.6);

            s1.add(new Month(6, year), 120.8);

            s1.add(new Month(7, year), 115.3);

            s1.add(new Month(8, year), 130.9);

            s1.add(new Month(9, year), 131.7);

            s1.add(new Month(10, year), 140.2);

            s1.add(new Month(11, year), 141.8);

            s1.add(new Month(12, year), 160.6);

        }

        TimeSeriesCollection dataset = new TimeSeriesCollection();

        dataset.addSeries(s1);

        // Create JFreeChart

        JFreeChart chart = ChartFactory.createTimeSeriesChart("TITLE", "TIME AXIS LABEL",

                "VALUE AXIS LABEL", dataset, true, true, false);

        

        // 这里是关键

        XYPlot xyplot = (XYPlot) chart.getPlot();

        DateAxis domainAxis = (DateAxis) xyplot.getDomainAxis(); //x轴设置

        domainAxis.setTickUnit(new DateTickUnit(DateTickUnit.YEAR, 5, new SimpleDateFormat("yyyy")));

        // Output

        File outputFile = new File("SampleTimeSeriesChart.png");

        ChartUtilities.saveChartAsPNG(outputFile, chart, 500, 500);

    }

}

推荐这里,Jfreechart大全:

关于Javaxychart和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-12-05,除非注明,否则均为首码项目网原创文章,转载请注明出处。