Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6202445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:44:09+00:00 2026-05-24T04:44:09+00:00

I have a typical setup for displaying charts for MVC3 web page – Here

  • 0

I have a typical setup for displaying charts for MVC3 web page –

Here is the code for all the components.

Controller Code:

public ActionResult ShowChart() {

     myViewModel model = _myService.GetViewModel();
     return View(model);
}

View Model:

using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.UI.DataVisualization.Charting;

public class ViewModel {

     public List<Chart> Charts { get; set; }

}

View: (View.cshtml)

@foreach (System.Web.UI.DataVisualization.Charting.Chart chart in Model.Charts)
{
    @chart
}

Chart Builder:

This populates the View Model.

private List<Chart> BuildCharts(List<Dummy> chartData)
    {
        var charts = new List<Chart>();
        foreach (Dummy chart in chartData)
        {
            charts.Add(BuildChart(chart));
        }

        return charts;
    }

    private Chart BuildChart(Dummy chartData)
    {
        var data = new ChartData
        {
            Title = "Chart X",
            xValues = chartData.hours,
            yValues = chartData.values
        };

        return ConfigureChart(data);
    }

    private Chart ConfigureChart(ChartData data)
    {
        Chart chart = new Chart(); 
        chart.Width = 150; 
        chart.Height = 300; 
        chart.Attributes.Add("align", "left"); 
        chart.Titles.Add(data.Title); 
        chart.ChartAreas.Add(new ChartArea());
        chart.Series.Add(new Series());
        chart.Legends.Add(new Legend("XXXX_YYY"));
        chart.Legends[0].TableStyle = LegendTableStyle.Auto;
        chart.Legends[0].Docking = Docking.Bottom;
        chart.Series[0].ChartType = SeriesChartType.Line;

        chart.Series[0].BackGradientStyle = GradientStyle.DiagonalLeft;
        chart.Series[0].BackSecondaryColor = System.Drawing.Color.LightGray;

        for (int i = 0; i < data.xValues.Length; i++)     
        {        
            string x = data.xValues[i];
            decimal y = data.yValues[i];

            int ptIdx = chart.Series[0].Points.AddXY(x, y);

            DataPoint pt = chart.Series[0].Points[ptIdx];
            pt.Url = "/Instance/Index/";
            pt.ToolTip = "Tooltip";
            pt.LegendText = "#VALX: #VALY";
            pt.LegendUrl = "/Contact/Details/";
            pt.LegendToolTip = "Click to view dummy information...";
        }

        return chart; 
    }

But, the code – @chart in the view does not render the chart. what I get in the page is a string ‘System.Web.UI.DataVisualization.Charting.Chart’ in place of the chart image.

Can somebody let me know what is wrong here. How can I output the chart on the view?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:44:11+00:00Added an answer on May 24, 2026 at 4:44 am

    You can’t do:

    @chart
    

    Asp.Net MVC does not know how to render those. What you can do is either request each chart as an image. So follow this tutorial.

    You should also move the “Option A” or “Option B” section into an editor template.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.