locked
draw graph with mschart by splting data RRS feed

  • Question

  • User923723782 posted

    hi all.i am working on a project which is for drawing a graph with data that are comming from n instrument that measures decible of the place. i want to store the measurements in my database bue the question is here: my database has just two columns.one is PK and its name is graphid and is for setting the number of the graph,ex :graph number one has graphid=1 and so on.so when for every test(one graphid) i want to store the decibles in another column with "decible" name.but i want to store decible measures like this: 12,45,56,67,...i mean i want to store them in just one column and seperate it with comma..please jelp me how i can store the data like this and how to read it? i know  string.split but i do not know how to use it and how to assign it to my Yvauenumber of my chart. plereease help me.i am in trouble.

    thanks

    Sunday, May 3, 2009 3:34 AM

Answers

  • User854688209 posted

     If double is working, loop throug string and converting the data in double.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 4, 2009 3:07 AM
  • User923723782 posted

    hi and thank you all.i solved my problem with this:

    string st ="12,45,56,67"; // comes from database

    string [] arrString = st.Split(new char[] {','});

    double[] arrDouble = new double[arrString.Length];for(int i=0; i<arrString.Length; i++)

    {

    arrDouble[i] =
    double.Parse(arrString[i]);

    }

    chart1.Series["Series1"].Points.DataBindY(arrDouble);

    chart1.Series["Series1"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;

     it draw a line chart for me.thank you all for your help and time.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 4, 2009 7:11 AM

All replies

  • User-2074802862 posted

     ok

    u can do in this way 

    first stored ur value in one strin say s1

    then create string array s2 

    say 

    dim s2 as string[]=s1.split( ',' )

    now use for loop to attach this values to graph in this way

    for i =0 to s2.length

    chart.Data.Add(New WebChart.ChartPoint( i+1&"position value", s2[i]))

    next

    Sunday, May 3, 2009 9:44 AM
  • User923723782 posted

    ity is in vb  i am a c# programmer ,i tried to convert it, but something is wrong,there is no chart.data.add.......  i could not  figure it out,could you please help me in c#.thanks

    Sunday, May 3, 2009 12:00 PM
  • User854688209 posted

    string strValue ="12,45,56,67";

    string[] arrStr = strValue.Split(',');

    for(int i = 0;i <=arrStr.Length; i++)
    {
          myChart.Data.Add(new WebChart.ChartPoint(i.ToString(), arrStr[i]))
    }

    Refer below links to know more:

    http://www.carlosag.net/Tools/WebChart/sampleCode.aspx

    http://www.carlosag.net/Tools/WebChart/imagelinemarker.aspx

    Sunday, May 3, 2009 12:12 PM
  • User923723782 posted

    i anm working on windows application and the webchart is webchart and it errors me to missing namespaces.also i am using mschart control,couldn1t i assign the arraylist(arrStr) to my mschart control?help me how.i tried this code:

    chart1.Series["Series1"].YValueMembers = "arrStr" but it does not help and show me aan empty chart.help pleeeeeeeeease.

    Sunday, May 3, 2009 1:23 PM
  • User854688209 posted

    Try this;

    string strValue ="12,45,56,67";

    string[] arrStr = strValue.Split(',');

    for(int i = 0;i <=arrStr.Length; i++)
    {
          chart1.Series["Series1"].YValueMembers = arrStr[i];

     

    Sunday, May 3, 2009 1:41 PM
  • User-2074802862 posted

     have u add Chart.dll file in ur toolbox ......

    add it first and then drop down that controll in ur design view ,it will work 

    and code for the c# is below

    string s1;

    string [] s2=s1.split( ' , ' ) ;

    for (int i=0; i< s1.length ;i++)

    {

      chart.Data.Add(New WebChart.ChartPoint(i.tostring+"Posion",s2[i]));
      }

    i hop this will help you

    Monday, May 4, 2009 1:09 AM
  • User923723782 posted

    hi.i tried it but it error me this at the last line: Index was outside the bounds of the array.

    is anyone test it before?i really confused what should i do

    Monday, May 4, 2009 1:49 AM
  • User854688209 posted

     My mistake, i have corrected it and marked it as bold

    string strValue ="12,45,56,67";

    string[] arrStr = strValue.Split(',');

    for(int i = 0;i <=arrStr.Length - 1; i++)
    {
          chart1.Series["Series1"].YValueMembers = arrStr[i];

    }

     

    Monday, May 4, 2009 1:53 AM
  • User923723782 posted

    i test it again but it show me a blank white  chart without axis and anything,i think there is something missing.i have to say that this code is working for a double array:

    double [] array = { 2.8, 4.4, 6.5, 8.3, 3.6, 5.6, 7.3, 9.2, 1.0};
     
    // Bind the double array to the Y axis points of the data series.
    Chart1.Series["Series1"].Points.DataBindY(array);

     but about my daa that is string and coming from database i don`t know.!!!!!!!!!!!!!!!!
    Monday, May 4, 2009 2:43 AM
  • User854688209 posted

     If double is working, loop throug string and converting the data in double.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 4, 2009 3:07 AM
  • User-2074802862 posted

     make it S2.length-1 in for loop

    Monday, May 4, 2009 4:06 AM
  • User923723782 posted

    what do you mean of s2.Lenght-1  ?what is s2? if you mean my array , i have done it like this :

    for(i=0;i<=arrstr.Lenght-1;i++)

    but it shows me an empty chart.i do not know what to do more? 

    Monday, May 4, 2009 5:24 AM
  • User-2074802862 posted

      i just want to know that ur using asp.net2.0 or 3.5

     next if ur using asp.net2.0 then u have to add chartcontoll.dll file ok 

     if ur using asp.net 2.0 give ur email id will mail u the  Graphcontroll.dll that i have

    and for 3.5 i m sorry i m still using asp.net 2.0

    THIS IS tested Code and Giving me the graph

    protected void Page_Load(object sender, EventArgs e)
        {
            string s1 = "12,10,13,20,100";
            string[] ss = s1.Split(',');
            WebChart.ColumnChart chart=new WebChart.ColumnChart() ;
            for (int i = 0; i < ss.Length - 1; i++)
            {
                float f_num = float.Parse(ss[i]);

                chart.Data.Add(new WebChart.ChartPoint(Convert.ToString(i), f_num));
              
            }
            
                ChartControl1.Charts.Add(chart);
                ChartControl1.RedrawChart();
        }
    Monday, May 4, 2009 6:07 AM
  • User923723782 posted

    hi and thank you all.i solved my problem with this:

    string st ="12,45,56,67"; // comes from database

    string [] arrString = st.Split(new char[] {','});

    double[] arrDouble = new double[arrString.Length];for(int i=0; i<arrString.Length; i++)

    {

    arrDouble[i] =
    double.Parse(arrString[i]);

    }

    chart1.Series["Series1"].Points.DataBindY(arrDouble);

    chart1.Series["Series1"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;

     it draw a line chart for me.thank you all for your help and time.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 4, 2009 7:11 AM
  • User854688209 posted

     Hi narina,

    Please mark the post as answer which helped you in resolving the issue, so that other can refer for same kind of issue.

    Monday, May 4, 2009 8:00 AM
  • User-468310695 posted

    hi i want to draw graph for that i required dllthis is my mail id akkineni.damodhar@gmail.com 

    is it possible to find the area between two lines

    do need full

    Saturday, May 30, 2009 2:16 AM