ASP.Net MVC C#画图 页面调用

/C# 后台代码

public FileContentResult PieChart()
        {
            TransactionStatisticsBLL bll = new TransactionStatisticsBLL();
            TransactionStatistics_Query query = new TransactionStatistics_Query();
            GetQuery(query);
            query.Stock = Request["SecuCode"];
            query.InfoType = Request["InfoType"];
            List<EM_DataCenter_TransactionStatistics> lst = bll.GetTOP5DJJMData(query);
            List<EM_DataCenter_TransactionStatistics> lst1 = GetYYBTOP(lst).Take(4).ToList();
            Chart chart1 = new Chart();
            Color backColor = ColorTranslator.FromHtml("#171717");

            chart1.BackColor = backColor;
            chart1.Width = 390;
            chart1.Height = 130;
            chart1.ChartAreas.Add("area1");
            chart1.Series.Add("金额占比");
            chart1.Series["金额占比"].CustomProperties = "DoughnutRadius=45, PieDrawingStyle=Concave, CollectedLabel=Other, MinimumRelativePieSize=40";
            chart1.Series["金额占比"].ChartType = SeriesChartType.Pie;
            chart1.Series["金额占比"]["DoughnutRadius"] = "30";
            chart1.Series["金额占比"]["PieLabelStyle"] = "Inside";

            if (lst1 != null && lst1.Count > 0)
            {
                double surplus = 1;
                foreach (EM_DataCenter_TransactionStatistics nv in lst1)
                {
                    DataPoint dp1 = new DataPoint();
                    var percent = (double)(nv.NetBuy1Amount / nv.NetBuyTotalAmount);
                    surplus -= percent;
                    dp1 = new DataPoint();
                    dp1.YValues = new double[] { percent * 100 };
                    dp1.LegendText = string.Concat((nv.Buy1.Length <= 6 ? nv.Buy1 : nv.Buy1.Substring(0, 6) + "..."), " (", StringTools.DecimalFormat(decimal.Parse((percent * 100).ToString())), "%)");
                    chart1.Series["金额占比"].Points.Add(dp1);
                }
                DataPoint dp2 = new DataPoint();
                dp2 = new DataPoint();
                dp2.YValues = new double[] { surplus * 100 };
                dp2.LegendText = string.Concat("其他", " (", StringTools.DecimalFormat(decimal.Parse((surplus * 100).ToString())), "%)");
                chart1.Series["金额占比"].Points.Add(dp2);
            }

            chart1.ChartAreas[0].BackColor = backColor;

            chart1.ChartAreas[0].Position = new ElementPosition(4, 0, 50, 90);
            chart1.Legends.Add("leg2");

            chart1.Legends[0].BackColor = backColor;
            chart1.Legends[0].ForeColor = ColorTranslator.FromHtml("#D0D0D0");

            chart1.Legends[0].Font = new System.Drawing.Font("宋体", 9, FontStyle.Regular);
            chart1.Legends[0].Position = new ElementPosition(55, 4, 50, 90);

            chart1.DataBind();
            MemoryStream memory = new MemoryStream();
            chart1.SaveImage(memory, ChartImageFormat.Jpeg);
            var bdata = memory.ToArray();
            memory.Dispose();
            return new FileContentResult(bdata, "image/Jpeg");
        }

 

/页面调用

$(obj).attr("src", "path/PieChart?SecuCode=" + secucode + "&InfoType=" + infotype + "&random=" + Math.round(Math.random() * 100));

转载于:https://www.cnblogs.com/evablog/p/chart.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值