找回密码
 立即注册

QQ登录

只需一步,快速开始

wp_pandy

高级会员

34

主题

166

帖子

1788

积分

高级会员

积分
1788

活字格认证

wp_pandy
高级会员   /  发表于:2012-9-27 18:24  /   查看:5341  /  回复:1
今天看了一个帖子,说的是图表,自己就也写了个,根据网上提供的事例,我用的是fpchart,但当我把数据源指定给它的时候,却不能运行,说fpchart不能序列化。代码如下:
前台:
<FarPoint:FpChart ID="FpChart1" runat="server" Height="320px" Width="320px">
            <Model>
                <LabelAreas>
                    <FarPointabelArea AlignmentX="0.5" Location="0.5, 0.02" />
                </LabelAreas>
                <LegendAreas>
                    <FarPointegendArea AlignmentX="1" AlignmentY="0.5" Location="0.98, 0.5" />
                </LegendAreas>
                <lotAreas>
                    <FarPoint:YPlotArea Elevation="15" GlobalAmbientLight="50,50,50" Location="0.2, 0.2"
                        Rotation="-20" Size="0.6, 0.6">
                        <YAxes>
                            <FarPoint:ValueAxis>
                            </FarPoint:ValueAxis>
                        </YAxes>
                        <Series>
                            <FarPoint:BarSeries />
                        </Series>
                        <Lights>
                            <FarPointirectionalLight AmbientColor="128,128,128" DiffuseColor="128, 128, 128"
                                DirectionX="10" DirectionY="20" DirectionZ="30" />
                        </Lights>
                    </FarPoint:YPlotArea>
                </PlotAreas>
            </Model>
        </FarPoint:FpChart>
后台代码:
//设置数据源
            DataTable dt = new DataTable("Test");
            DataRow dr = default(System.Data.DataRow);
            dt.Columns.Add("名称");
            dt.Columns.Add("数量");

            dr = dt.NewRow();
            dr[0] = "电器";
            dr[1] = 0.2;
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr[0] = "服装";
            dr[1] = 0.5;
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr[0] = "家具";
            dr[1] = 0.3;
            dt.Rows.Add(dr);

            //设置 BarSeries
            FarPoint.Web.Chart.BarSeries series = new FarPoint.Web.Chart.BarSeries();

            //设置图表展示数据
            series.Values.DataSource = dt;
            series.Values.DataField = dt.Columns[1].ColumnName;

            //使用多样化颜色显示
            series.VaryColors = true;

            //设置 X 轴显示名称
            series.CategoryNames.Add("电器");
            series.CategoryNames.Add("服装");
            series.CategoryNames.Add("家具");
            series.LabelVisible = true;

            //设置 YPlotArea
            FarPoint.Web.Chart.YPlotArea plotArea = new FarPoint.Web.Chart.YPlotArea();
            //设置显示单位为 20%
            //plotArea.YAxes[0].DisplayUnits = 0.5;

            //设置 Y 轴显示为 Percentage
            plotArea.YAxes[0].LabelNumberFormat = "00.0%";

            //设置 YPlotArea 显示位置
            plotArea.Location = new System.Drawing.PointF(0.2F, 0.2F);
            //设置 YPlotArea 大小
            plotArea.Size = new System.Drawing.SizeF(0.6F, 0.6F);

            plotArea.Series.Add(series);

            //设置图例
            LegendArea legend = new LegendArea();
            legend.Location = new PointF(0.98f, 0.5f);
            legend.AlignmentX = 1.0f;
            legend.AlignmentY = 0.5f;

            //设置图表标签
            LabelArea label = new LabelArea();
            label.Text = "产品分布";
            label.Location = new PointF(0.5f, 0.02f);
            label.AlignmentX = 0.5f;
            label.AlignmentY = 0.0f;

            FarPoint.Web.Chart.ChartModel model = new FarPoint.Web.Chart.ChartModel();
            model.PlotAreas.Add(plotArea);
            model.LegendAreas.Add(legend);
            model.LabelAreas.Add(label);
            FpChart1.EnableViewState = true;
            FpChart1.ViewType = ChartViewType.View3D;
            FpChart1.Model = model;

1 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2012-9-28 11:07:00
沙发
回复 1楼wp_pandy的帖子

请问你如果运行:http://gcdn.grapecity.com/showtopic-4849.html 中的 Demo 会出现以上问题吗?
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部