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 7837977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:56:18+00:00 2026-06-02T14:56:18+00:00

I am creating some charts in my ASP.NET WebForms aplication and for create the

  • 0

I am creating some charts in my ASP.NET WebForms aplication and for create the charts in my application, and for the chart’s data, I have to write strings for the datatables (in javascript) like:

var data = new google.visualization.DataTable();
data.addColumn('date', 'Date');
data.addColumn('number', 'Sold Pencils');
data.addColumn('string', 'title1');
data.addColumn('string', 'text1');
data.addColumn('number', 'Sold Pens');
data.addColumn('string', 'title2');
data.addColumn('string', 'text2');
data.addRows([
  [new Date(2008, 1 ,1), 30000, null, null, 40645, null, null],
  [new Date(2008, 1 ,2), 14045, null, null, 20374, null, null],
  [new Date(2008, 1 ,3), 55022, null, null, 50766, null, null],
  [new Date(2008, 1 ,4), 75284, null, null, 14334, 'Out of Stock', 'Ran out of stock on pens at 4pm'],
  [new Date(2008, 1 ,5), 41476, 'Bought Pens', 'Bought 200k pens', 66467, null, null],
  [new Date(2008, 1 ,6), 33322, null, null, 39463, null, null]
]);

I’m using SqlDataReaders to do this, creating this dirty code:

string jsGraph = "";
jsGraph += "data.addRows([";
            while (dsChartsData.Read())
            {
                var d = (DateTime)dsChartsData["dateColumn"];
                jsGraph += "[new Date(" + d.Year.ToString() + ", " + d.Month.ToString() + ", " + d.Day.ToString() + "), " + dsChartsData["value1"].ToString() + ", null, null, " + dsChartsData["value3"].ToString() + ", null, null],";
            }
jsGraph += "]);"

Is there any way to do this more maintainable, with a clean code and easy to debug? (javascript in .cs files is a big mess in my code, million of concatenations and stuff)

Obs: Currently I’m using webForms but if some of you have a great advantage doing this with MVC, please tell me, maybe I can create pages in MVC only to renderize charts (after learning that, of course).

  • 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-06-02T14:56:20+00:00Added an answer on June 2, 2026 at 2:56 pm

    First of all, you are missing the separation comma , from your javascript array…

    Secondly, why so much concatenations? Why not a public variable and call it from javascript?

    like:

    public string graphData = "";
    

    In your method:

    StringBuilder jsGraph = new StringBuilder();
    jsGraph.AppendLine("[");
    
    while (dsChartsData.Read())
    {
        var d = (DateTime)dsChartsData["dateColumn"];
        jsGraph.AppendLine("[new Date(" + d.Year.ToString() + ", " + d.Month.ToString() + ", " + d.Day.ToString() + "), " + dsChartsData["value1"].ToString() + ", null, null, " + dsChartsData["value3"].ToString() + ", null, null],");
    }
    jsGraph.AppendLine("]");
    
    graphData = jsGraph.ToString();
    

    and in your Javascript:

    var graphData = <%= graphData %>;
    ...    
    data.addRows(graphData);
    

    BTW, your big concatenation should be written as:

    jsGraph.AppendFormat(
                "[new Date({0:yyyy, M, d}), {1}, null, null, {2}, null, null],", 
                  (DateTime)dsChartsData["dateColumn"], 
                  dsChartsData["value1"],
                  dsChartsData["value3"]);
    

    witch can be much easier to read.

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

Sidebar

Related Questions

I am creating some cookies in my ASP.NET application. These cookies expire 10 minutes
I'm using fusioncharts free and creating some 3d pie charts like so... <div style=margin:0
I'm creating some scripts to streamline application installations and I need to append to
I am creating some tag functionality for a forum using linq2sql, and I have
I'm creating some custom application logs in my web application with log4net for my
I am able to place multiple charts on a chart sheet by creating an
I'm creating some data as a string in a webservice and returning that string
Im looking for some help creating a graph using the google chart API I
So I have this application in ASP MVC 3. My database has two tables:
I'm a building a web application in java. I have to create an applet

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.