簡體   English   中英

在C#中將十進制[]轉換為雙精度[]

[英]Conversion of decimal[ ] to double [ ] in c#

我正在使用以下代碼在asp.net-mvc4應用程序中進行繪圖

System.Web.UI.DataVisualization.Charting.Chart chart = new System.Web.UI.DataVisualization.Charting.Chart();

        chart.BackColor = Color.Transparent;
        chart.Width = Unit.Pixel(700);
        chart.Height = Unit.Pixel(420);
        chart.BackColor = Color.FromArgb(211, 223, 240);
        chart.BorderlineDashStyle = ChartDashStyle.Solid;
        chart.BackSecondaryColor = Color.White;
        chart.BackGradientStyle = GradientStyle.TopBottom;
        chart.BorderlineWidth = 1;
        chart.Palette = ChartColorPalette.BrightPastel;
        chart.BorderlineColor = Color.FromArgb(26, 59, 105);
        chart.RenderType = RenderType.BinaryStreaming;
        chart.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
        chart.AntiAliasing = AntiAliasingStyles.All;
        chart.TextAntiAliasingQuality = TextAntiAliasingQuality.Normal;

        Series series1 = new Series("Series1");
        series1.ChartArea = "ca1";
        series1.ChartType = SeriesChartType.Line;
        series1.Font = new Font("Verdana", 8.25f, FontStyle.Regular);

        series1.Points.Add(new DataPoint
        {
            AxisLabel = "Value1",
            YValues = new double[] { 100 }
        });

        series1.Points.Add(new DataPoint
        {
            AxisLabel = "Value2",
            YValues = new double[] { 500 }
        });

        chart.Series.Add(series1);

        ChartArea ca1 = new ChartArea("ca1");
        ca1.BackColor = Color.Transparent;
        chart.ChartAreas.Add(ca1);

        using (var ms = new MemoryStream())
        {
            chart.SaveImage(ms, ChartImageFormat.Png);
            ms.Seek(0, SeekOrigin.Begin);

            return File(ms.ToArray(), "image/png", "mychart.png");
        }

現在,我將數據點作為數據庫中的數組保存在returnValue 我添加了如下編輯的數據點

series1.Points.Add(new DataPoint
        {
            AxisLabel = "Value1",
            YValues = new double[] {returnValue.yData}
        });

錯誤是

Conversion from decimal[] to double is not possible

使用Convert.ToDouble:

series1.Points.Add(new DataPoint
{
    AxisLabel = "Value1",
    YValues = returnValue.yData.Select(Convert.ToDouble).ToArray()
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM