zoukankan      html  css  js  c++  java
  • 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));

  • 相关阅读:
    第二次站立会议6
    第二次冲刺计划会议5
    第二次冲刺计划会议4
    第一次冲刺计划总结
    历史分割
    并查集
    archetype mvn 创建骨架
    protobuf 实战
    grizzly 实战
    RSA 非对称加密
  • 原文地址:https://www.cnblogs.com/evablog/p/chart.html
Copyright © 2011-2022 走看看