User interactive Graph from DataGridView - c#

I have a DataGridView that displays information that is read from a txt file. My aim is to create a line graph for this data which displays DateTime for the X axis.
My aim is to create the graph so it shows the information from the Gridview onto the graph. The user can then select points on the graph that then show them specific info from that part of the data for example a row.
I am not sure which API to use for this:
I have tried using internal Chart functions for Visual Studio but I can not interact the selectable part onto the graphs I created.
If anyone has any advice on how to do this would be great.

Your question seems to have several parts. I'll try to help with each..
The last part in your question is solved like this:
Assuming you have a Chart with the DataPoints set and showing the line, you can use this:
Series S = chart1.Series[0]; // short reference
S.ToolTip = "#VALX{#.##}" + " : " + "#VALY1{#.##}";
to display the x- and y-values as tooltips in a format you like.
See MSDN for a full list of keywords to use in referring to the DataPoints
If you want to display data that are not part of the DataPoint's data you can instead create individual ToolTips for each DataPoint when you add it:
double dx = yourXValue;
double dy = yourYValue;
DataPoint dp = new DataPoint(dx, dy);
dp.ToolTip = yourToolTip;
S.Points.Add(dp);
You will have to create the ToolTip readily formatted for each DataPoint!
If other parts are still open, please say so!

Related

Infragistics StackColumnChart show the wrong value

I need an explanation about Infragistics, which I don't understand. I want to display several bars in a chart per month. The whole thing will be in my opinion a StackColumnChart:
But is displayed incorrectly.
If I run the whole thing as a ColumnChart they are displayed correctly:
Is it possible that I get the same display also in the StackColumnChart?
Actually your chart is configured to show data values on charted items. This is how the data is organized on the Stacked Column Chart. But this default behavior you can change according to your requirements.
Make the following changes.
I suppose you already have the Infragistics.UltraChart.Resources.Appearance.ChartTextAppearance chartTextAppearance1 declaration. If not you can add it by using the Chart Wizard.
The chartTextAppearance1 will added later to the column chart appearance like that:
columnChartAppearance1.ChartText.Add(chartTextAppearance1);
Set the chartTextAppearance1.ItemFormatString to <DATA_VALUE_ITEM>:
chartTextAppearance1.ItemFormatString = "<DATA_VALUE_ITEM>";
This make it work as you was asking.
Some additional information you can find here: Label Formatting

How to display start and end points x-axis label in a chart in c# windows forms?

I am just a rookie at C# windows forms application. I am trying to plot a chart from a data table using the function this.chart1.Series[0].Points.DataBindXY(dt.DefaultView, "tms", dt.DefaultView, head[1]); where dt is the data table, tms is timestamp column and head[1] is a data column. But I am not able to see the start and end x-axis label in chart. Check out my output here. i.e. I want to see the timestamp of start and end of the data. So how do I do it? Is there any predefined function?
Thanks for helping...
There is no predefined function, but
1) if your data is in some 'good' time interval, i.e. from 2020.05.01 0:00 to 2020.05.02 03:00, you can tune AxisX.Minimum and AxisX.Interval properties.
2) if your data is not in 'good' time interval you should use CustomLabels. It is not so easy because your CustomLabels override all normal labels.
3) if it is only necessary to show the first and the last values, and it is not important where - use RectangleAnnotation - text that can be placed on chart.
The easiest way for any data type is to set the IsMarginVisible property of the X axis to false:
chartArea1.AxisX.IsMarginVisible = false;
or
Property Box

Calculating a range of User Inputed values (Unspecified amount) in a textbox created grid

In this assignment I have to create a spreadsheet like excel without importing a library. Now So far I created a grid of 26x26 textboxes (USING CODE), created the indexed rows and alphabet indexed columns. (All of this using a class named Cellfields as a template)
Gave the names (A1,A2,A3 etc) to each cell. and created a formula bar up top.
then I created an if statement that if what the user writes.SubString(0) == to "=" (Meaning the start of a formula),
it will then go to a switch to read the other input the user entered, meaning if user enters =Sum(A1:A3) it will calculate the sum of cells A1,A2,A3.
Now since the calculated cells required are unspecified, I am unable to find a solution to how to calculate a range of values online, as all you can find online are how to import libraries.
I Did try a few things but were immediately removed. I am trying to create a method for it however, have been staring at laptop for the past 3 days.
So you already have a matrix of 26x26 Textboxes, I assume they would be arranged in a Grid, say the name of your Grid is "gridCells".
Now, Users will click on a Cell (actually textbox) and then go to the Formula Bar and type a formula. So On GotFocus of the textboxes, let the textbox remain "Selected", in the sense keep the reference at form level also may be Highlight the Border to show that this is the currently selected cell. This will help you know which Textbox to apply the formula.
Now, when someone types "=Sum(A1:A3)" in the Formula Bar, you would parse the formula, identify it is a "Sum" operation and find out the names of the Textboxes A1, A2 & A3.
From your post looks like you are done this far. Now write a function as below (Not bothering about performance etc. right now).
private String GetValueOfCell(String cellName)
{
foreach (var control in gridCells.Children.OfType<TextBox>())
if (control.Name.Equals(cellName))
return control.Text;
return "";
}
Call this function for all 3 Textboxes, like this:
String value = GetValueOfCell("A1");
And if the value is not empty and can be parsed as int/double, keep doing the Sum and finally store the value in the Text property of our highlighted Textbox.
Hint: You might also want to Save the Formula on the highlighted textbox, because this value goes into the Text property you can use the Tag property to hold the formula.

Filter and display Google Map Markers from database based on DropDownList selection in ASP.Net

in our project we need to show the markers on Google map from the database. we have already got the code in which all the markers are displayed for the the places stored in database. But our aim is somewhat different.We need marker on one place that is selected from the database.to elaborate,if we select an area from the dropdownlist that contains names of areas stored in database,then "only" marker on that place must be displayed.Further,selecting the subarea from dropdownlist2 should zoom the map and display a marker on that subarea.so how do we do that?
Awaiting your rply.
The best possible and simple way I can think of to solve this issue is to have multiple colored markers for specific region or area you want to make distinction. this would automatically draw a line of difference in between tow area's (If this can also be a solution for you).
For code implementation have a look at this example.
we just need to add the following code in the selectedIndexChange event of the DropDownList1 so that it will return the filtered records.
DataTable dt = this.GetData("select [Name], [Latitude], [Longitude] from [MAIN AREA] WHERE [Name] ='" + DropDownList1.SelectedItem.Text+"'");
rptMarkers.DataSource = dt;
rptMarkers.DataBind();

How to reset the MSCHart values

I have a combo-box which contains different names of files and every time i select a value the respective file should be read and respective graphs should be generated. Now as i select the first file the charts are drawn correctly but if i select another value from the combo-box then the charts instead of re-plotting the charts values are added to the existing values..
I tried using serializer but that doesn't seem to work...neither i am able to find a solution anywhere.
Just need to know what i need to add as to reset the existing chart to default value and redraw on every combo-box selection.
You'll need to clear the values from each of your Series.
chart.Series["MySeries"].Points.Clear();
foreach (var series in chart2.Series)
{
series.Points.Clear();
}

Categories