Web图表开发-用ChartDirector画饼状图

对比习惯于JFreeChart开发的人,这家伙显得简单、明了。 ChartDirector画饼状图方法非常简单,只需简单的几个部署,下面是代码:

Java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// 设置Chart大小、背景色  
PieChart pc = new PieChart( 750 , 500 , 0xddddff ,- 1 , 1 );  
pc.setPieSize( 390 , 245 , 150 );  
   
// 设置图表标题  
// 只要将文字转成UTF-8编码就可以解决中文乱码问题  
// 另外如果你将程序部署到Linux下就需要copy相应的字体文件,比如simsun.ttc文件到/usr/share/font下  
TextBox t = null ;  
pc.setDefaultFonts( "SIMSUN.TTC" , "simhei.ttf" );  
t = pc.addTitle(rb.get( "REPORT_TOTAL_PURCHASED" ), "" , 14 ); // 中文就从resource.properties中取吧  
t.setBackground( 0xaaaaff ); // 字体也要有背景的  
t.setBackground( 0xaaaaff , 0xaaffaa ); // 需要加边框吗?加上第二个参数就可以了  
t.setHeight( 30 );  
   
StringBuffer sb = new StringBuffer(RetrainingConstant.get( "total_join" ))  
      .append(data[data.length- 1 ]).append(rb.get( "rein" ));  
   
TextBox total = pc.addText( 10 , 35 , sb.toString()); // 加个文字吧,随便显示什么都行了  
total.setFontColor( 0x000000 );  
total.setFontSize( 10 );  
   
double [] data = new double []{ 100 , 90 , 80 , 70 };  
String[] labels = new String[]{ "ColumnA" , "ColumnB" , "ColumnC" , "ColumnD" };  
   
pc.setData(dt,labels); // 放数据  
   
double [] depths1 = { 45 , 10 , 35 , 20 , 25 , 30 , 15 , 40 };  
pc.set3D2(depths1);  
pc.setLabelLayout(Chart.SideLayout);  
   
// 每一块饼都得给个说明  
TextBox t1 = pc.setLabelStyle();  
t1.setBackground(Chart.SameAsMainColor, Chart.Transparent, Chart.glassEffect());  
t1.setRoundedCorners( 5 );  
pc.setLineColor(Chart.SameAsMainColor, 0x000000 );  
pc.setStartAngle( 225 );  
   
// 最终的img.src  
getRequest().setAttribute( "chartURL" , pc.makeSession(getRequest(), "chartURL" ));  
// 链接的href,其中变量{dataSetName}和{value}分别对应了data和lables中的值  
getRequest().setAttribute( "imageMap" ,pc.getHTMLImageMap( "searchStudents.html" ,  
         "chartType=5&subject={dataSetName}" , "title='{value}人'" ));  
            
// 至此,饼图就被搞定了~~ 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
web页上绘制饼图曲线图等组件(c#) 例子: 生成饼图表******************************************** private void InitializeComponent() { this.myBarGraph.RenderGraph += new ZedGraph.Web.ZedGraphWebControlEventHandler(this.OnRenderGraphBar); this.myLineGraph.RenderGraph += new ZedGraph.Web.ZedGraphWebControlEventHandler(this.OnRenderGraphLine); } private void OnRenderGraphBar(ZedGraphWeb zgw, System.Drawing.Graphics g, ZedGraph.MasterPane masterPane) { myBarMethod(zgw, g, masterPane, strYear, strMonth, compareType); } private void OnRenderGraphLine(ZedGraphWeb zgw, System.Drawing.Graphics g, ZedGraph.MasterPane masterPane) { myLineMethod(zgw, g, masterPane, douYear, douMonth); } private void myBarMethod(ZedGraphWeb zgw, System.Drawing.Graphics g, ZedGraph.MasterPane masterPane, string[] strYear, string[] strMonth, string compareType) { GraphPane myPane = masterPane[0]; myPane.Title.Text = title + "柱状图分析"; myPane.XAxis.Title.Text = "时间(月/年)"; if (compareType == "AddValue") { myPane.YAxis.Title.Text = "增加值"; } else { myPane.YAxis.Title.Text = "增加比例(%)"; } List<PointPairList> ListPointParitList = new List<PointPairList>(); for (int i = 0; i < strYear.Length; i++) { ListPointParitList.Add(new PointPairList()); } int n = 0; for (double x = 0; x < strMonth.Length; x += 1.0) { for (int i = 0; i < strYear.Length; i++) { //ListPointParitList[i].Add(x, randNum[n++] * multiplyValue); ListPointParitList[i].Add(x, GetFXData(strYear[i], strMonth[(int)x])); } } List<BarItem> ListBarItem = new List<BarItem>(); List<Color> ListColor = GetColor(); for (int i = 0; i < strYear.Length; i++) { ListBarItem.Add(new BarItem(strYear[i], ListPointParitList[i], ListColor[i])); ListBarItem[i] = myPane.AddBar(strYear[i], ListPointParitList[i], ListColor[i]); } myPane.XAxis.MajorTic.IsBetweenLabels = true; myPane.XAxis.Scale.TextLabels = strMonth; myPane.XAxis.Type = AxisType.Text; myPane.Fill = new Fill(Color.White, Color.FromArgb(200, 200, 255), 45.0f); myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f); masterPane.AxisChange(g); }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值