ZedGraphグラフィックコントロールのWeb開発における応用
31642 ワード
:dreamliner
Email:[email protected]
2008
-
5
-
20
ZedGraph , 2D ,bar, pie , Windows Form , ASP.NET Web Form 。ZedGraph , , , 。ZedGraph .NET
2
.0 Visual Studio 2005 。
Visual Studio 2005 UpdatePanel,ZedGraph Web Web , 。 Web , 。
Visual Studio 2005
Visual Studio 2005 File
->
New Web Site, 1 , ASP.NET AJAX
-
Enabled Web Site ( , Visual Studio 2005 ASPAJAXExtSetup ), File System, ZedGraphDemo, Ok。
1 ASP.NET AJAX
-
Enabled
Toolbox ZedGraph
Toolbox , Choose Items…, Choose Toolbox Items Browse , ZedGraph.Web.dll ( zedgraph_dll_v5.
1.2
.
880
)。
Default.aspx Design , UpdatPanel,Timer( Timer UpdatePanel , , ) ZedGraphWeb , Design 2 。 Timer1 Interval 1000, 。
2
ZedGraph
ZedGraph 。 Visual Studio , 。 1 Visual Studio 。 Height
300
Width
400
RenderedImagePath
~/
ZedGraphImages
/
ChartFill.Color
Black
ChartFill.Type
Solid
TmpImageDuration
(Gets or sets a value that determines the duration (
in
hours) of a temporary file generated by control
in
mode
"
ImageTag
"
)
0
, 。
1 Visual Studio ZedGraph
, New Folder, ZedGraphImages,ZedGraph , 。
DataSource.cs , , Visual Studio App_Code , “ ” 。 , ,Visual Studio 。 PointPairList , using ZedGraph; ZedGraph 。 :
。
namespace
DataModal
{
public
class
DataSource
{
private
DataSource() { dataPoints
=
101
; }
public
static
readonly
DataSource Instance
=
new
DataSource();
private
Random ran
=
new
Random();
//
public
PointPairList DataBuffer
=
new
PointPairList();
///
<summary>
///
,
///
</summary>
///
<param name="datas"></param>
public
void
GetData()
{
double
[] yData
=
new
double
[DataPoints];
//
for
(
int
i
=
0
; i
<
DataPoints; i
++
)
{
yData[i]
=
100
*
ran.NextDouble();
}
//
double
[] xData
=
new
double
[DataPoints];
for
(
int
i
=
0
; i
<
DataPoints; i
++
)
{
xData[i]
=
i;
}
DataBuffer
=
new
PointPairList(xData, yData);
}
///
<summary>
///
///
</summary>
private
UInt32 dataPoints;
public
UInt32 DataPoints
{
get
{
return
dataPoints; }
set
{ dataPoints
=
value; }
}
}
}
1
.
Default.aspx.cs , ZedGraph , , using System.Drawing;
using
ZedGraph;
using
ZedGraph.Web;。
2
.
_Default , , , 。
static
LineItem myCurve;
static
DataModal.DataSource osc
=
DataSource.Instance;
3
. ZedGraph RenderGraph
, ZedGraph ? , RenderGraph 。 ZedGraph , “ ” , RenderGraph ,Visual Studio 。 Default.aspx.cs ,
protected
void
ZedGraphWeb1_RenderGraph(ZedGraph.Web.ZedGraphWeb webObject, System.Drawing.Graphics g, ZedGraph.MasterPane pane){}
。ZedGraph MasterPane , , MasterPane , pane[
0
] 。
, ZedGraph ( : Visifire ( Silverlight ) , , ZedGraph , ZedGraph 。 Web ,Visifire ZedGraph 。 ZedGraph , , , 。 Web , , 。 , 。)
3 Visifire , Visifire , ZedGraph 。 2 , X Y 。
3 Scale.Max
Scale.Min
MajorStep
the scale step size
for
this
Scale (the increment between labeled axis values)
,
0,
1
,
2
,…
100
, 10 tic(major tic), MajorStep 10, 10 。
Scale.BaseTic
the scale value at which the first major tic label will appear
MajorGrid.IsVisible
MajorGrid.Color
MajorGrid.DashOff
The dash off length
is
defined
in
points (
1
/
72
inch)
0, 。
Scale.Mag
, x, x
*
10Mag
2
ZedGraphWeb1_RenderGraph , , myPane ,ZedGraph 。
protected
void
ZedGraphWeb1_RenderGraph(ZedGraph.Web.ZedGraphWeb webObject, System.Drawing.Graphics g, ZedGraph.MasterPane pane)
{
GraphPane myPane
=
pane[
0
];
//
X
//
X
myPane.XAxis.Scale.Max
=
DataSource.Instance.DataPoints
-
1
;
myPane.XAxis.Scale.Min
=
0
;
//
myPane.XAxis.Scale.BaseTic
=
0
;
//
X
myPane.XAxis.Scale.MajorStep
=
(DataSource.Instance.DataPoints
-
1
)
/
10
;
//
X
myPane.XAxis.Scale.IsVisible
=
true
;
//
, ^1,
//
myPane.XAxis.Scale.Mag = 1;
//
Y
//
Y
myPane.YAxis.Scale.Max
=
110
;
myPane.YAxis.Scale.Min
=
0
;
//
myPane.YAxis.Scale.BaseTic
=
0
;
//
X
myPane.YAxis.Scale.MajorStep
=
10
;
//
X
myPane.YAxis.Scale.IsVisible
=
true
;
//
myPane.XAxis.MajorGrid.IsVisible
=
true
;
myPane.YAxis.MajorGrid.IsVisible
=
true
;
myPane.XAxis.MajorGrid.Color
=
Color.LightGray;
myPane.YAxis.MajorGrid.Color
=
Color.LightGray;
myPane.YAxis.MajorGrid.DashOff
=
0
;
myPane.XAxis.MajorGrid.DashOff
=
0
;
//
myCurve
=
myPane.AddCurve(
"
"
, osc.DataBuffer, Color.Yellow, SymbolType.None);
}
4
. Timer Tick
Tick , , , ZedGraph , 。
protected
void
Timer1_Tick(
object
sender, EventArgs e)
{
//
DataSource.Instance.GetData();
//
this
.ZedGraphWeb1.AxisChanged
=
true
;
}
5
.
ZedGraphDemo , 4 :
4
Web
Web Service , 5 , Web Service , WebControlService。
5 Web Service
WebControlService.cs , 。 DataSource, DataModal。 JavaScript Web , WebControlService [ScriptService] , using System.Web.Script.Services;。 ScriptManager Web , ScriptManager :
<
asp:ScriptManager ID
=
"
ScriptManager1
"
runat
=
"
server
"
>
<
Services
>
<
asp:ServiceReference Path
=
"
WebControlService.asmx
"
/>
</
Services
>
</
asp:ScriptManager
>
[WebMethod]
[ScriptMethod]
public
void
SetPoints(
string
points)
{
DataSource.Instance.DataPoints
=
Convert.ToUInt32(points);
}
[WebMethod]
[ScriptMethod]
public
UInt32 GetPoints()
{
return
DataSource.Instance.DataPoints;
}
Defualt.aspx , 。
<
asp:Literal ID
=
"
Literal1
"
runat
=
"
server
"
Text
=
"
"
></
asp:Literal
><
br
/>
<
input id
=
"
txtPoints
"
type
=
"
text
"
onchange
=
"
ontxtPointsValueChange()
"
/>
, JavaScript Script.js, Default.aspx (
<
head
/>
<
script type
=
"
text/javascript
"
src
=
"
Script.js
"
></
script
>
)。
ZedGraphDemo , 6 :
6
, , 120( , ), , , 120?
, , , 。 ZedGraph , ZedGraph 。
…
。
…
UpdatePanel , 。 JavaScript Web UpdatePanel 。
, 5 。 demo, , , Email 。