Luke Belbina
Luke Belbina

Reputation: 5859

ASP MVC3 Charting (A Step Backwards)?

I attemtping to use Charts in MVC 3 and asside from the default ChartThemes provided it seems way harder to specify themes. There is no longer a way to edit ChartAreas or access many strongly typed properties (the argument type for chart area is just a string).

Previously you could do something like this:

Old Way

    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 }
      };

New Way

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

The chart area data is now just a string and you have chart themes are a string and there are a few defaults.

This seems like a massive step backwards? Am I missing something fundamental?

Upvotes: 0

Views: 1262

Answers (3)

Sean Campbell
Sean Campbell

Reputation: 177

I think you'll find the the default themes are just that. You still have the ability to override styling by substituting your own chartarea xml. Take a look here at the ChartTheme reference

Upvotes: 0

Mangesh
Mangesh

Reputation: 3997

I agree the Charts helpers is very basic. Dundas charts provided a better way of doing things.

Microsoft acquired Dundas Data Visualization Intellectual Property in April 2007 and is integrating this technology in different Microsoft products since then.

These still sends images a better alternative is HighCharts which is build on javascript.

Upvotes: 0

Tridus
Tridus

Reputation: 5081

No, the chart helper is pretty weak. But you can still do it the old way using the Data Vizualization package. Of course, that package is extremely poorly documented. Here's something to help get you started at least.

Upvotes: 1

Related Questions