flex实现股票行情走势图示例代码

 
第一步:
jsp:1


代码如下:

<%@page import="java.util.Random,java.util.GregorianCalendar"%>
<?xml version="1.0" encoding="utf-8"?>
<items>
<%
GregorianCalendar calendar = new GregorianCalendar();
int year = calendar.get(calendar.YEAR);
int month = calendar.get(calendar.MONTH) + 1;
int today = calendar.get(calendar.DAY_OF_MONTH);
String strday=year+","+month+","+today+",";
int sb = 400;
String[] dates = new String[] {strday+"14,60"};

String crutime=request.getParameter("time");
///crutime=crutime.replace(":",",");
if(crutime!=null){
crutime=crutime.replace(":",",");
dates = new String[] {strday+crutime};

}
for (int i = 0; i < dates.length; i++) {
Random random = new Random();
int r = random.nextInt(1000);
%>
<item> <value>
<%
if (i < 10) {
%><%=r%>
<%
}
%>
</value> <date><%=dates[i]%></date> <sb><%=sb%></sb> </item>
<%
}
%>
</items>

jsp:2


代码如下:

<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
String path = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<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">
<SCRIPT language="JScript.Encode" src="Js/SwfObject.js" type="text/javascript"></SCRIPT>
</head>
<body topmargin="0" leftmargin="0">
<div align="center" style="margin-top: 40;">
<div id="flashcontent" width="600" height="400" align="center" ></div>
<script type="text/javascript">
var so = new SWFObject("<%=path%>/testfrist.swf", "Main", "600", "400","9.0", "#ffffff", "high");
so.addVariable("myAmfurl","<%=path%>/nxsy.jsp");
so.addVariable("myAmtitle","牛熊双赢");
so.write("flashcontent");
</script>
</div>
</body>
</html>

第二步flex代码:


代码如下:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="100%" backgroundColor="white" creationComplete="init();">
<mx:Style>
.font12{font-family:宋体;fontSize:15}

.lenchar{
bar-color:red;
}

.mypanelTitle {
color: #66ccff;
fontFamily: Comic Sans MS;
fontWeight: normal;
textDecoration: underline;
}
</mx:Style>
<mx:Script><![CDATA[
import flash.sampler.getMemberNames;
import mx.charts.chartClasses.IAxis;
import mx.charts.LinearAxis;
import mx.charts.HitData;
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
import mx.charts.renderers.CircleItemRenderer;
import mx.graphics.Stroke;
import mx.controls.DateField;
[Bindable]
private var myAmfurl:String = ""; //用于连接到外部页面
[Bindable]
private var myAmtitle:String = ""; //用于连接到外部页面
[Bindable]
public var testDatas:ArrayCollection=new ArrayCollection();
[Bindable]
private var expenses:ArrayCollection = new ArrayCollection();
[Bindable]
private var arr:Array = new Array();
[Bindable]
private var mintime:Date;
[Bindable]
private var maxtime:Date;
[Bindable]
private var smintime:Date;
[Bindable]
private var emaxtime:Date;
private var timer:Timer;
private var stocksb:Number;
private var dateVar:Date;
private var d: Date = new Date();
private function init():void{

// setInterval(torequest,2000);
myAmfurl = Application.application.parameters.myAmfurl; //风险追溯链接
myAmtitle=Application.application.parameters.myAmtitle;
timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER, torequest)
timer.start();

}
public function torequest(et:Event):void{
setstyle();
realtimeservice.send();
}
//用于设置样式
public function setstyle():void{

}
private function formatDataTip(hitData:HitData):String
{
var s:String = hitData.item.date.toString();
var a:Array = s.split(",");
var str:String=a[3]+":"+a[4];
str += "\n";
str += hitData.item.value;
return str;
}
private function parseDate(value:String):Date{

var a:Array = value.split(",");
var newDate:Date = new Date(a[0],a[1],a[2],a[3],a[4]);

return newDate;
}

private function getResult(e:ResultEvent):void{
var min:String="";

var pattern:RegExp=/,/gi;
for each (var resultXML:XML in e.result.item){

var tmpobj:Object=new Object();
tmpobj.value=resultXML.value;
tmpobj.date=resultXML.date;
tmpobj.sb=resultXML.sb;
stocksb=Number(tmpobj.sb);
var str=tmpobj.date;
var a:Array = str.split(",");
mintime= new Date(a[0],a[1],a[2],9,30);
smintime= new Date(a[0],a[1],a[2],11,30);
min=tmpobj.date;
maxtime=new Date(a[0],a[1],a[2],15,00);
emaxtime=new Date(a[0],a[1],a[2],13,00);
if(expenses.length==0){
expenses.addItem(tmpobj);
}else{
var check:int=0;
if(expenses.length>0){
for each(var subtempobj:Object in expenses){
if(String(subtempobj.date).replace(pattern,"")==String(tmpobj.date).replace(pattern,"")){
check=1;
}
}
}
if(check==0){
expenses.addItem(tmpobj);
check=0;
}
}

}
var tmpobj1:Object=new Object();
var tmpobj2:Object=new Object();
var a:Array = min.split(",");
tmpobj1.value=stocksb;
tmpobj1.date=a[0]+","+a[1]+","+a[2]+","+"9,30";
tmpobj2.value=stocksb;
tmpobj2.date=a[0]+","+a[1]+","+a[2]+","+"15,00";
testDatas.addItem(tmpobj1);
testDatas.addItem(tmpobj2);
}
private function mylabel(labelValue:Object, previousValue:Object, d:IAxis):String {
var temp:String="";
var currvalue:Number = Number(labelValue.toString());
if(currvalue>stocksb){
temp = '<font color="#ff0000" size="11">'+labelValue.toString()+'</font>';
}else{
temp = '<font color="#48ff00" size="11">'+labelValue.toString()+'</font>';
}
return temp;
}

]]></mx:Script>
<!-- Define custom Strokes. -->
<mx:Stroke id = "s1" color="#FFFFFF" weight="0.1"/>
<mx:Stroke id = "s2" color="#F1F1B8" weight="1"/>
<mx:Stroke id = "s3" color="green" weight="1"/>
<mx:Stroke id="vstroke" color="red" weight="1" alpha="0.6"/>

<mx:HTTPService result="getResult(event);" id="realtimeservice" url="{myAmfurl}" useProxy="false" resultFormat="e4x" method="POST">

</mx:HTTPService>

<mx:Panel title="{myAmtitle}" fontSize="15" height="100%" width="100%" color="red" backgroundColor="#000000" borderStyle="inset">

<mx:LineChart styleName="lenchar" dataTipFunction="formatDataTip" showDataTips="true" height="100%" width="100%" id="chart" fontFamily="宋体" fontSize="12">
<mx:backgroundElements>
<mx:GridLines direction="both">
<mx:horizontalStroke>
<mx:Stroke color="red" weight="1" alpha="0.6"/>
</mx:horizontalStroke>
<mx:verticalStroke>
<mx:Stroke color="red" weight="1" alpha="0.2"/>
</mx:verticalStroke>
</mx:GridLines>
</mx:backgroundElements >
<!-- vertical axis -->
<mx:verticalAxis>
<mx:LinearAxis id="va" baseAtZero="false" title="" labelFunction="mylabel"/>
</mx:verticalAxis>
<mx:horizontalAxis>
<!--mx:CategoryAxis id="ca" categoryField="date" displayName="date" title="date" /-->
<!--mx:LinearAxis displayName="date" minimum="1" id="ca" interval="10"/ -->
<!--<mx:DateTimeAxis dataUnits="seconds" interval="30" minimum="{minDate}" maximum="{maxDate}"/>-->

<!--<mx:DateTimeAxis id="hAxis" parseFunction="parseDate" interval="1" minimum="{mintime}" maximum="{maxtime}" displayLocalTime="true" dataInterval="1" dataUnits="hours" labelUnits="hours" />-->
<mx:DateTimeAxis id="hAxis"
disabledDays="{[0,6]}"
disabledRanges="{[{rangeStart:smintime, rangeEnd:emaxtime}]}"
parseFunction="parseDate" interval="1" minimum="{mintime}" maximum="{maxtime}" displayLocalTime="true" dataInterval="30" dataUnits="minutes" labelUnits="minutes"

/>
</mx:horizontalAxis>
<!-- horizontal axis renderer -->
<mx:horizontalAxisRenderers>
<mx:AxisRenderer axis="{hAxis}" canDropLabels="true" axisStroke="{vstroke}" />
</mx:horizontalAxisRenderers>

<mx:verticalAxisRenderers>
<mx:AxisRenderer axis="{va}" canDropLabels="true" axisStroke="{vstroke}" />
</mx:verticalAxisRenderers>

<!-- series -->
<mx:series>
<mx:LineSeries id="series" yField="value" xField="date" displayName="value" dataProvider="{this.expenses}" lineStroke="{s1}" />
<mx:LineSeries yField="value" xField="date" displayName="TestData" dataProvider="{this.testDatas}" lineStroke="{s2}" />
</mx:series>
</mx:LineChart>

</mx:Panel>

</mx:Application>

(0)

相关推荐

  • flex实现股票行情走势图示例代码

     第一步:jsp:1 复制代码 代码如下: <%@page import="java.util.Random,java.util.GregorianCalendar"%> <?xml version="1.0" encoding="utf-8"?> <items> <% GregorianCalendar calendar = new GregorianCalendar(); int year = cal

  • Flex中通过RadioButton进行切换示例代码

    1.页面切换 复制代码 代码如下: <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx&quo

  • flex动态加载swf皮肤示例代码

    复制代码 代码如下: <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minW

  • flex渐变色制作圆角橙色按钮示例代码

    复制代码 代码如下: <?xml version="1.0" encoding="utf-8"?> <s:SparkButtonSkin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:fb="http://ns.adobe.com/flashbuilder/2009

  • Flex调Javascript打开新窗口示例代码

    测试应用TestJavascript.mxml 复制代码 代码如下: <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adob

  • bootstrap轮播图示例代码分享

    本文实例为大家分享了bootstrap轮播图的具体代码,供大家参考,具体内容如下 <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="view

  • java 自动生成略缩图示例代码

    当你要做一个图库的项目时,对图片大小.像素的控制是首先需要解决的难题.一.单图生成略缩图单图经过重新绘制,生成新的图片.新图可以按一定比例由旧图缩小,也可以规定其固定尺寸.详细代码如下: 复制代码 代码如下: <SPAN style="FONT-SIZE: 14px">import com.sun.image.codec.jpeg.JPEGImageEncoder;import com.sun.image.codec.jpeg.JPEGCodec;import com.su

  • Android版的股票行情K线图开发

    现在在手上的是一个证券资讯类型的app,其中有涉及到股票行情界面,行情中有K线图等,看到网上很多人在求这方面的资料,所以我特地写了一个demo在此处给大家分享一下. 下面是做出来的效果图: 背景图是利用canvas先画出一个矩形,然后再画几根虚线,均线图是通过path来绘制的,总之图的绘制是很简单的,我就不在这里作介绍了,大家可以去github下载源码看看.涉及到均线.最高价.最低价.收盘价.开盘价的概念大家可以百度一下. 我再这里要介绍的是计算问题: 大家可以看到分时图.日K.月K的左边的成交

  • 用vue写一个仿简书的轮播图的示例代码

    1.先展示最终效果: 2.解决思路 Vue的理念是以数据驱动视图,所以拒绝通过改变元素的margin-top来实现滚动效果.写好css样式,只需改变每张图片的class即可实现轮播效果.动画效果交给transition完成.可以将轮播图看成两个(mainSlide和extraSlide),各个图片的位置如图所示: 3.代码实现 各个slide的样式: $width: 800px; // 容器宽度 $height: 300px; // 容器高度 $bWidth: 500px; // 大图片宽度 $

  • JavaScript实现无缝轮播图的示例代码

    目录 上效果 一.实现过程 1)首先实现基本布局 2)主要样式 二.如何实现无缝呢 (重点来了) 思路: 主要代码 完整代码 花费一个下午从0到1实现的轮播图,当然还有很多需要改进的地方(欢迎提出需要改进的地方),等我再努力努力,将其封装成一个组件. 上效果 一.实现过程 1)首先实现基本布局 <div class="carousel-container"> //图片列表 <div class="carousel-list"></div

随机推荐