ASP MVC3制图(向后退一步)?

时间:2011-07-19 21:15:07

标签: asp.net-mvc-3 charts

我决定在MVC 3中使用Charts并从默认的ChartThemes中获得帮助,因为它似乎更难指定主题。不再有办法编辑ChartAreas或访问许多强类型属性(图表区域的参数类型只是一个字符串)。

以前你可以这样做:

旧方式

    ChartArea area = new ChartArea {
        BackColor = Color.Transparent,
        AxisX = new Axis {
          Interval = 7,
          IntervalType = DateTimeIntervalType.Days,
          IsMarginVisible = false,
          LabelStyle = new LabelStyle { ForeColor = Color.FromArgb(255, 128, 128, 128), Font = new Font("Arial", 10, FontStyle.Regular), Format = "MMM dd" },
          LineColor = Color.FromArgb(255, 208, 208, 208),
          MajorGrid = new Grid { LineColor = Color.FromArgb(255, 242, 242, 242), LineDashStyle = ChartDashStyle.Solid },
          MajorTickMark = new TickMark { LineColor = Color.Transparent, Size = 4.8f }
        },
        AxisY = new Axis {
          IntervalAutoMode = IntervalAutoMode.VariableCount,
          LabelStyle = new LabelStyle { ForeColor = Color.FromArgb(255, 128, 128, 128), Font = new Font("Arial", 10, FontStyle.Regular) },
          LineColor = Color.Transparent,
          MajorGrid = new Grid { LineColor = Color.FromArgb(255, 242, 242, 242), LineDashStyle = ChartDashStyle.Solid },
          MajorTickMark = new TickMark { LineColor = Color.Transparent, Size = 0.8f }
        },
        Position = new ElementPosition { Height = 90, Width = 99, X = 0, Y = 10 }
      };

新方法

Chart chart = new Chart(width: 400, height: 200, theme: ChartTheme.Yellow)
                .AddSeries(
                    chartType: "line",
                    xValue: dates.ToArray(),
                    yValues: data.ToArray(),
                    chartArea: someString)

图表区域数据现在只是一个字符串,您的图表主题是一个字符串,并且有一些默认值。

这似乎是倒退一大步?我错过了一些基本的东西吗?

3 个答案:

答案 0 :(得分:1)

不,图表助手非常弱。但您仍然可以使用Data Vizualization包以旧方式执行此操作。当然,这个包的记录非常糟糕。 Here's something to help get you started at least.

答案 1 :(得分:0)

我同意图表助手是非常基本的。 Dundas图表提供了更好的做事方式。

Microsoft于2007年4月收购了Dundas Data Visualization Intellectual Property,并且从那时起将该技术集成到不同的Microsoft产品中。

这些仍会发送图像 一个更好的选择是HighCharts,它建立在javascript上。

答案 2 :(得分:0)

我想你会发现默认主题就是这样。您仍然可以通过替换自己的chartarea xml来覆盖样式。在ChartTheme参考

上查看here