Click here to Skip to main content
15,884,974 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a csv file in the following format
date,openemr
23-09-2014 04:56:14,1
23-09-2014 04:56:15,1
23-09-2014 04:56:18,1
23-09-2014 04:56:18,1
23-09-2014 04:56:19,1
23-09-2014 04:56:20,1
23-09-2014 04:56:23,1
23-09-2014 04:56:26,1
23-09-2014 04:56:27,1
23-09-2014 04:56:28,1
23-09-2014 04:56:30,1
23-09-2014 04:57:03,1
23-09-2014 04:57:06,1
23-09-2014 04:57:06,1
23-09-2014 04:57:06,1
23-09-2014 04:57:07,1
23-09-2014 04:57:08,1
23-09-2014 04:57:09,1
23-09-2014 04:57:11,1
23-09-2014 04:57:13,1
23-09-2014 04:57:15,1

i have gone through many articles but am unable to draw a chart it is coming like undefined on x axis, i have used am chart library,i don't have much knowledge on java script, can someone please help me out in creating a line chart using some nice library.Thanks In Advance
Posted
Comments
Mehdi Gholam 7-Oct-14 3:26am    
Chart of the above will be a straight line and shows nothing useful.
Chinna Suresh 7-Oct-14 4:49am    
its a part of the csv file, it has other values but am unable to generate a graph
Kornfeld Eliyahu Peter 7-Oct-14 6:01am    
1. Turn that CSV into ADO.NET data source
2. Pick your favorite chart control
3. bind 2 to 1...
Chinna Suresh 7-Oct-14 6:24am    
how can use that csv to draw line chart using some libraries..like i have tried drawing line chart using chart control but it has very pathetic look,i just want to have some nice UI so.

1 solution

Use the sample Code for displaying the line chart:

HTML Code:
<asp:label id="Label8" runat="server" text="Line Chart" xmlns:asp="#unknown"></asp:label>
                        <br />
                    <div id="chart_div8">
                        <asp:literal id="lt8" runat="server" xmlns:asp="#unknown"></asp:literal>
                    </div>

C# Code: 
public void Line_Chart1()
    {
        StringBuilder str4 = new StringBuilder();
        //string sql = "select * from tmp_feedback";
        string sql = "select itemid,round(avg(rating)) as rating from tmp_feedback group by itemid";
        DataSet ds = new DataSet();
        OracleDataAdapter adp = new OracleDataAdapter(sql, conn);
        adp.Fill(ds, "tmp_feedback");
        DataTable dt = new DataTable();
        dt = ds.Tables[0];
        try
        {
            adp.Fill(dt);
            str4.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', 'ITEMID');
            data.addColumn('number', 'RATING');

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

            Int32 i;
            for (i = 0; i <= dt.Rows.Count - 1; i++)
            {
                str4.Append("data.setValue( " + i + "," + 0 + "," + "'" + dt.Rows[i]["ITEMID"].ToString() + "');");
                str4.Append("data.setValue(" + i + "," + 1 + "," + dt.Rows[i]["RATING"].ToString() + ") ;");
            }
            str4.Append("   var chart = new google.visualization.LineChart(document.getElementById('chart_div8'));");
            str4.Append(" chart.draw(data, {width: 300, height: 300, title: 'Performance Rating',");
            str4.Append("vAxis: {title: 'Rating', titleTextStyle: {color: 'green'}}");
            str4.Append("}); }");
            str4.Append("</script>");
            lt8.Text = str4.ToString().TrimEnd(',').Replace('*', '"');
            conn.Close();
        }
        catch
        {

        }
        finally
        {
            conn.Close();
        }
    }
 
Share this answer
 

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