Ext写的一个折线图

先看一下效果图:


现在显示的是三条曲线,可以通过修改TipsChart.js来实现线的条数,运用Ext,首先需要的就是引入Ext中的相关文件,这个就不提了,相信对Ext有所了解的都知道需要引那几个文件

下面贴上代码:

index.jsp------------------------------

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/Ext/resources/css/ext-all.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/Ext/resources/css/example.css" />
    <style>
        .x-tip {
        background-color: #fff;
        border-radius: 0.5em;
        -moz-border-radius: 0.5em;
        -webkit-border-radius: 0.5em;
        border-radius: 0.5em;
        border: 1px solid rgba(134, 84, 41, 0.5);
        opacity: 0.95;
    }
    .x-tip-header {
        margin-bottom: 5px;
    }
    .x-tip .x-panel .x-panel-body.x-layout-fit {
        border: none;
    }
    .x-tip .x-panel.x-grid-section.x-panel-noborder.x-fit-item {
        margin: 0;
    }
    .x-tip .x-panel.x-box-item {
        top: 0 !important;
    }
    .x-tip-header-body .x-component.x-box-item {
        width: 100%;
        text-align: center;
    }
    .x-tip-body {
        text-shadow: none;
    }
    .x-panel {
            margin: 20px;
        }
    ul {
        margin-left: 10px;
    }
    ul li {
        display: block;
        font-weight: normal;
        color: #444;
        padding: 2px;
    }
    h1 {
        font-size: 18px;
        margin: 10px;
    }
    </style>
    <script type="text/javascript" src="${pageContext.request.contextPath }/Ext/bootstrap.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath }/Ext/example-data.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath }/Ext/TipsChart.js"></script>
  </head>
  <body id="docbody">
  </body>
</html>

TipsChart.js

Ext.require('Ext.chart.*');
Ext.require('Ext.layout.container.Fit');

Ext.onReady(function () {
    var panel1 = Ext.create('widget.panel', {
        width: 800,
        height: 400,
        title: '曲线图',
        renderTo: Ext.getBody(),
        layout: 'fit',
        items: [{
            xtype: 'chart',
            animate: true,
            shadow: true,
            store: store1,
            legend: {
               position: 'right'
            },
            axes: [{
                type: 'Numeric',
                minimum: 0,
                position: 'left',
                fields: ['2011', '2012', '2013'],
                title: '百分比',
                minorTickSteps: 1,
                grid: {
                    odd: {
                        opacity: 1,
                        fill: '#ddd',
                        stroke: '#bbb',
                        'stroke-width': 0.5
                    }
                }
            }, {
                type: 'Category',
                position: 'bottom',
                fields: 'name',
                title: '2013年物业曲线图'
            }],
             series: [{
                type: 'line',
                axis: 'left',
                gutter: 80,
                xField: 'name',
                yField: '2011',
                markerConfig: {
                    type: 'circle',
                    'stroke-width': 0
                }
            },{
                type: 'line',
                axis: 'left',
                smooth: true,
                xField: 'name',
                yField: '2012',
                markerConfig: {
                    type: 'circle',
                    'stroke-width': 0
                }
            },{
                type: 'line',
                axis: 'left',
                smooth: true,
                xField: 'name',
                yField: '2013',
                markerConfig: {
                    type: 'circle',
                    'stroke-width': 0
                }
            }]
        }]
    });
});

其中Ext中自带的example-data.js文件我做了修改:

Ext.onReady(function() {
    window.generateData = function(n, floor){
        var data = [],i;
        for (i = 0; i < (n || 12); i++) {
            data.push({
                name: i+1+'月份',
                2011: Math.floor(Math.max(Math.random() * 100)),
                2012: Math.floor(Math.max(Math.random() * 100)),
                2013: Math.floor(Math.max(Math.random() * 100))
            });
        }
        return data;
    };
    window.store1 = Ext.create('Ext.data.JsonStore', {
        fields: ['name', '2011', '2012', '2013'],
        data: generateData()
    });    
});

好了,所有代码已上传 微笑

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值