Visifire实现统计图

        /// <summary>
        /// 柱形图
        /// </summary>
        public static Chart InitCompareChart(string fundName, string tenThousandRate, string sevenRate)
        {
            Chart CompareChart = new Chart();
            CompareChart.Theme = "Theme3";
            Visifire.Charts.Title t = new Visifire.Charts.Title();
            t.Text = string.Format("{0}与存款收益比较", fundName);
            CompareChart.Titles.Add(t);

            DataSeries dataSeries = new DataSeries { RenderAs = RenderAs.Bar };
            dataSeries.LabelEnabled = true;
            dataSeries.LegendText = "每万元单日收益";
            double tenThousandAccrual = 0;
            Double.TryParse(tenThousandRate, out tenThousandAccrual);
            dataSeries.DataPoints.Add(new DataPoint { AxisXLabel = fundName, YValue = tenThousandAccrual });
            dataSeries.DataPoints.Add(new DataPoint { AxisXLabel = "定期五年", YValue = 1.3014 });
            dataSeries.DataPoints.Add(new DataPoint { AxisXLabel = "定期三年", YValue = 1.1644 });
            dataSeries.DataPoints.Add(new DataPoint { AxisXLabel = "定期二年", YValue = 1.0274 });
            dataSeries.DataPoints.Add(new DataPoint { AxisXLabel = "定期一年", YValue = 0.8219 });
            dataSeries.DataPoints.Add(new DataPoint { AxisXLabel = "定期半年", YValue = 0.7671 });
            dataSeries.DataPoints.Add(new DataPoint { AxisXLabel = "定期三月", YValue = 0.7123 });
            dataSeries.DataPoints.Add(new DataPoint { AxisXLabel = "活期", YValue = 0.0959 });

            DataSeries dataSeries2 = new DataSeries { RenderAs = RenderAs.Bar };
            dataSeries2.LabelEnabled = true;
            dataSeries2.LegendText = "七日年化收益率";
            double qiRiAnnualizedYield = 0;
            Double.TryParse(sevenRate.Replace("%", ""), out qiRiAnnualizedYield);
            dataSeries2.DataPoints.Add(new DataPoint { AxisXLabel = fundName, YValue = qiRiAnnualizedYield });
            dataSeries2.DataPoints.Add(new DataPoint { AxisXLabel = "定期五年", YValue = 4.75 });
            dataSeries2.DataPoints.Add(new DataPoint { AxisXLabel = "定期三年", YValue = 4.25 });
            dataSeries2.DataPoints.Add(new DataPoint { AxisXLabel = "定期二年", YValue = 3.75 });
            dataSeries2.DataPoints.Add(new DataPoint { AxisXLabel = "定期一年", YValue = 3.00 });
            dataSeries2.DataPoints.Add(new DataPoint { AxisXLabel = "定期半年", YValue = 2.80 });
            dataSeries2.DataPoints.Add(new DataPoint { AxisXLabel = "定期三月", YValue = 2.60 });
            dataSeries2.DataPoints.Add(new DataPoint { AxisXLabel = "活期", YValue = 0.35 });

            CompareChart.Series.Add(dataSeries);
            CompareChart.Series.Add(dataSeries2);

            return CompareChart;
        }

        /// <summary>
        ///折线统计图
        /// </summary>
        public static Chart InitTenThousandRateChart(string fundName, List<FundDay> fundDayList)
        {
            Chart TrendChart = new Chart();
            TrendChart.Theme = "Theme3";
            Visifire.Charts.Title t = new Visifire.Charts.Title();
            t.Text = string.Format("{0}单日万元收益走势", fundName);
            TrendChart.Titles.Add(t);

            DataSeries AccrualSeries = new DataSeries { RenderAs = RenderAs.Line };
            AccrualSeries.LabelEnabled = true;
            AccrualSeries.LegendText = "每万元单日收益";

            int listCount = fundDayList.Count;
            int dayIndex = (listCount >= 7) ? 6 : listCount;//限定最多只能取七天的数据做走势图,并且保证时间轴(X轴)的最右端是最新日期

            if (listCount > 0)
            {
                while (dayIndex >= 0)
                {
                    FundDay fundDay = fundDayList[dayIndex];

                    string date = fundDay.Date.Substring(fundDay.Date.IndexOf("-") + 1);

                    double tenThousandAccrual = 0;
                    Double.TryParse(fundDay.TenThousandRate, out tenThousandAccrual);
                    AccrualSeries.DataPoints.Add(new DataPoint { AxisXLabel = date, YValue = tenThousandAccrual });

                    dayIndex--;
                }
            }

            Axis a = new Axis();
            a.StartFromZero = false;
            TrendChart.AxesY.Add(a);

            TrendChart.Series.Add(AccrualSeries);

            return TrendChart;
        }
原文地址:https://www.cnblogs.com/AlvinLiang/p/4987566.html