-5

I had to do some calculations on data that I had pulled from a database. I now have an Double Array with 24 data points. Is there a way to plot this information onto an existing chart I have in my site?

using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.DataVisualization.Charting;
using System.Web.UI.WebControls;

public partial class _Default : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Get data for limits
        DataView avgLim = avgLimits.Select(DataSourceSelectArguments.Empty) as DataView;
        DataTable averageLim = avgLim.ToTable();

        //Add data for single fill parts
        DataView dv = noDamper.Select(DataSourceSelectArguments.Empty) as DataView;
        DataTable singleDT = dv.ToTable();


        //Add data for Dampered Parts
        DataView dv1 = Damper.Select(DataSourceSelectArguments.Empty) as DataView;
        DataTable damperDT = dv1.ToTable();
        damperData.Series.Add("damperData");

        //Moving Average starts here
        //Calc moving data
        Double[] singleMovData = new Double[24];
        Double[] damperMovData = new Double[24];

        //GET DATA TO Column
        Double[] tempSingle = new Double[25];
        Double[] tempDamper = new Double[25];

        int j =0;
        foreach (DataRow row in singleDT.Rows)
            tempSingle[j++] = Convert.ToInt32(row[2]);//Convert.ToDouble(row[3]);
        j =0;
        foreach(DataRow row in damperDT.Rows)
            tempDamper[j++] = Convert.ToInt32(row[2]);

        for (int i = 0; i <= 23; i++)
        {
            singleMovData[i] = Math.Abs(Convert.ToDouble(tempSingle[i]) - Convert.ToDouble(tempSingle[i+1]));
            damperMovData[i] = Math.Abs(Convert.ToDouble(tempDamper[i]) - Convert.ToDouble(tempDamper[i + 1]));

        }

        //singleFillMoving.Series.Add("singleMov");
        //singleFillMoving.Series["singleMov"].ChartType = SeriesChartType.Line;
        singleFillMoving.DataSource = singleMovData;
        //singleFillMoving.Series.Add(singleMovData);
        singleFillMoving.DataBind();

        damperFillMoving.Series.Add("damperData");
        damperFillMoving.Series["damperData"].ChartType = SeriesChartType.Line;
        //damperFillMoving.Series["damperData"].XValueMember = "CONTAINER_ID";
        //damperFillMoving.Series["damperData"].YValueMembers = "DIFFERENCE";
        damperFillMoving.DataSource = damperMovData;
        damperFillMoving.DataBind();  

    }
}
  • 1
    Read your question and ask yourself, will you be able to answer the question if someone asked you exactly how have? with such little information – Izzy Aug 20 '15 at 16:10
  • @Izzy Not sure what else you need to know. I have an array. It is type Double. I need to put it in a chart that already exists and have data in it. I just want to know how to take the data that is in the array and plot it. – Garrett Rietveld Aug 20 '15 at 16:13
  • What type of chart do you have, what environment is it running in, what have you tried so far, what errors are you getting... All these things will help us to answer you. As it stands it **appears** you want us to do **your** work without you even thinking about it! – Troyseph Aug 20 '15 at 16:23
  • @GarrettRietveld For starters, we need to know what chart library you're using. There's thousands of them out there, each with their own way of loading data. We don't know if you're using a server side library to generate the chart, or a client side library. Again, ask yourself, if you saw someone ask this question, would you have enough information there to know where to start answering? – mason Aug 20 '15 at 16:23
  • @mason Its the default chart library in ASP. I am using nothing special. I am new to ASP, and have made alot of progress with this application, but I have been stumped for hours trying to figure out how to get these values plotted. – Garrett Rietveld Aug 20 '15 at 16:30
  • @Sebatian So dont say I'm just looking for someone to do it for me. I have spent hours trying to figure out how to do this, because this type of stuff wasn't originally in my job description. I've never had trouble finding someone to point me in the right direction without being an ass on here. – Garrett Rietveld Aug 20 '15 at 16:31
  • There is no "default chart library in ASP". I'm not saying you are trying to have someone do your work for you, I'm saying you didn't give enough information here to do your work, which makes it sound like you want us to do your work for you. You need to provide enough details to have the question be answerable. Show your code that generated the chart data, show your code that declares the chart on the page, show your attempt at adding the data to the chart. You need to edit all of this into your question, and tag the question with the appropriate library. – mason Aug 20 '15 at 16:32
  • @mason added my code. I never had to add anything to do the charts beyond the include for the using System.Web.UI.DataVisualization.Charting; So I don't know what else to give you. Like I said, I don't know this stuff. Give me java or C++ and I'll make it work, but they want it web based. – Garrett Rietveld Aug 20 '15 at 16:37
  • Whether it's Java or C++, you still have to provide enough relevant details in your question. Adding your code is a good start. Is there any associated .aspx markup? It looks like you have some code to add the data to your chart - how is that not working as you expect it to? Have you thought about creating a super simple example to test with? – mason Aug 20 '15 at 16:40
  • @mason Everything else works other than the two charts I need to input with the array. I've already done breakpoints and step throughs to make sure that there is data in the array. I just am not sure how to convert the array to a usable format to have the program plot. I didn't think I needed to give every piece of my code, because 90% of it isn't relevant. I just need to know how I can take an Array of Double values and plot them on a graph. – Garrett Rietveld Aug 20 '15 at 16:42
  • You're right, you don't need to give every piece of your code. You need to edit it down so that you have an [MCVE](http://stackoverflow.com/help/mcve). **Carefully read the MCVE link!** That's what I meant by "super simple example". – mason Aug 20 '15 at 16:47
  • @mason I give up. Why even try to argue. I shouldn't have needed to provide any code for some small request like this. Someone should have had to have coded something similar at some point or could at least point me to a different way of getting these points to the graph. The calculations are done, the graphs appear, there is just no data because the points aren't added. I get it that you are trying to help, but you have to be over thinking this, because my issue isn't that large, I just dont know how to resolve it. – Garrett Rietveld Aug 20 '15 at 16:51
  • I'm sorry that you feel that way. You need learn how to properly communicate issues. It's a useful skill, not just for Stack Overflow, but for working with other programmers in any capacity. A big part of that communication is learning to boil your issue down to exactly what your problem is, and this often involves creating a simplified example that demonstrates where you're stuck. It's really very simple to do that if you follow the MCVE instructions that I linked to above. – mason Aug 20 '15 at 16:54
  • @mason I can see that, but it isn't an issue with the way my items are set up. I have two other graphs that work perfectly fine using almost identical code. The only difference is that instead of a datatable, I now have an array of values that I performed some calculations on. I just don't know how to set the chart to use that array for the points. It accepted it as the dataSource, but it isn't plotting them. – Garrett Rietveld Aug 20 '15 at 16:57
  • But we don't need to see your other graphs. Which is why you need to *read* the MCVE page I linked to earlier and create a *minimal* example. Only show the code necessary. For example, show how you obtain your array, and show how you declare the chart, and show your attempt at adding the array of data to the chart. Anything else is extraneous and can be removed from your question's code. Your code obtaining the array should be in a seperate method too. All we really need to see of that part is `double[] data = GetData();` – mason Aug 20 '15 at 16:59
  • @mason Edited it down to the two graphs that are in question. They are similar in setup. In the ASP side of things there isn't much code other than a div holding the graphs and the initial graph name declaration. Everything else is on the C# side. – Garrett Rietveld Aug 20 '15 at 17:04
  • Okay, now I don't understand why you have two array? Are the arrays supposed to match on the index, so that combining each element from the array gives a single point? – mason Aug 20 '15 at 17:07
  • There are two different sets of data(different part types) I'm working with. – Garrett Rietveld Aug 20 '15 at 17:09
  • See, that's why it's useful to create a **Minimal** Complete, Verifiable example. If it's not minimal, it's hard to know exactly what it is that you're stuck on. – mason Aug 20 '15 at 19:20

1 Answers1

0
singleFillMoving.Series["singleMov"].Points.DataBindY(singleMovData);

That is the line of code I needed. Just needed to dig deep enough.