Click here to Skip to main content
14,870,739 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hii ,

C#
// Create and populate the data table.
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'department');
        data.addColumn('number', 'Draft');
        data.addColumn('number', 'InProgress');
        data.addColumn('number', 'Completed');

        data.addRows([
            ['IT', { v: 18, f: '18%' }, { v: 40, f: '40%' }, { v: 42, f: '42%' }],
            ['Administrative', { v: 40, f: '40%' }, { v: 30, f: '30%' }, { v: 30, f: '30%' }],
            ['Sales', { v: 35, f: '35%' }, { v: 10, f: '10%' }, { v: 55, f: '55%' }],
            ['Sales', { v: 15.5, f: '15.5%' }, { v: 65, f: '65%' }, { v: 19.5, f: '19.5%' }]

        ]);



How can i add this type of code dynamically from c#
i have check other chart from c# as below (below is just an example, in which i want to achive my above requirment)

C#
private void BindChart()
        {
            DataTable dt = new DataTable();
            try
            {
                dt = GetData();

                str.Append(@"<script type=text/javascript> google.load( *visualization*, *1*, {packages:[*corechart*]});
                google.setOnLoadCallback(drawChart);
                function drawChart() {
                var data = new google.visualization.DataTable();
                data.addColumn('string', 'department');
                data.addColumn('number', 'Draft');
                data.addColumn('number', 'InProgress');
                data.addColumn('number', 'Completed');

            data.addRows(" + dt.Rows.Count + ");");

                for (int i = 0; i <= dt.Rows.Count - 1; i++)
                {
                    str.Append("data.setValue( " + i + "," + 0 + "," + "'" + dt.Rows[i]["year"].ToString() + "');");
                    str.Append("data.setValue(" + i + "," + 1 + "," + dt.Rows[i]["Sales"].ToString() + ") ;");
                    str.Append("data.setValue(" + i + "," + 2 + "," + dt.Rows[i]["Expences"].ToString() + ") ;");
                }


can you please suggest me how to add my first requirements using for loop
Posted
Updated 29-Apr-15 4:22am
v2
Comments
Torakami 30-Apr-15 1:01am
   
Anything more information if needed to understand this question , please let me know .. i added the question as per my understanding .. Please suggest

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900