我正在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
答案 0 :(得分:1)
使用Convert.ToDouble:
series1.Points.Add(new DataPoint
{
AxisLabel = "Value1",
YValues = returnValue.yData.Select(Convert.ToDouble).ToArray()
});