Been struggling with this through out the day. I have three series on a chart that look like this. NOTE: I am using the winforms control.
The values are being added based on calculations from input. I am using this code to add the values to each series.
this.chart1.Series["green"].Points.AddY(greenvalue);
this.chart1.Series["totalsaving"].Points.AddY(totalsavingvalue);
this.chart1.Series["blue"].Points.AddY(bluevalue);
The series properties I have set like this. Green and totalsaving are both set to StackedColumn, blue is set to Column for chart type.
I then have a button to start over which brings the user back to the input area and I am then using this code to clear the series values on the start over click.
chart1.Series["totalsaving"].Points.Clear();
chart1.Series["green"].Points.Clear();
chart1.Series["blue"].Points.Clear();
The same calculation click is being used as above to calculate and populate the series data. The problem is when I click the calculate button to calculate the values after I have cleared them, the total savings, and the green are missing. Just the blue is shown.
Am I doing something wrong with the way I am trying to clear the values so I can re calculate?
OK, from the edits, comments, our chat and the joim.me session enough data has accumulated to answer the question.
You have twisted the display by adding an extra data point to the blue series in the designer.
This point occupies slot 1 but remains invisible as its value = 0.
This pushes the next point in the series to slot 2
After clearing the points it is gone and the display doesn't work anymore.
The disappearing of the two columns probably was caused by hard coded widths.
You have several paths you can follow:
recreating the extra point with value = 0 before adding the real data (not recommended)
not adding the extra point in the first place but forcing each point into its slot by using Points.AddXY instead of Points.AddY with X being the slot.
not clearing the points but updating their values by using the SetValueY method. After all three data points have beend assigned their new values you need to call chart1.Invalidate() to make it show.
Fore easiest styling of all those properties, some of which are deeply burried inside of property strings(!), you may even decide to add and style&polish all three points in the designer and only update their y-values like this:
chart1.Series["green"].SetValueY(greenvalue);
chart1.Series["totalsaving"].SetValueY(totalsavingvalue);
chart1.Series["blue"].SetValueY(bluevalue);
chart1.Invalidate();
The choice is yours, but in any case I recommend setting the proper X values, be it in code or in the desginer..
Related
I have generated a chart in asp.net c#, which gets user data from the database and display it. Now I want to add a line to it which can indicate the baseline set by the user. I think it might be a new series which will be drawn from start to end. It will be ideal if the user is able to change it and on changing the line is redrawn. I have dates on x-axis and activity time on y axis. In the following picture I want line like Goal. Any suggestions?
There are two ways I know which can be used to achieve this line.
One is by adding the tag but the line will appear under the bars.
If you want the line to appear above the bars then you need to add another series of type line chart. Make its x axis secondary and specify the values so that it appears as a straight line. Hide the lengends and labels etc for line chart.
I have a .net program that lets the user select a chart from a dropdown and a data range then queries sql for the data to display the chart, everything is fine unless they pick a date range that would only return 1 value for that particular chart.
When this happens since there is only 1 point on the graph it does not display anything for line or area charts (it does work on bar and column).
i have thought about forcing the graph type to column if there is only 1 data point but was wondering if there was a setting i am missing that would allow a straight line on a line graph if there was only 1 datapoint.
well based on the idea of faking a 2nd point i came up with this that technically does what i want it to do.
this is called when there is only 1 point
foreach (Series ser in mainChart.Series)
{
ser.Points.AddY(ser.Points[0].YValues[0]);
}
I thought i might should add in case anyone else needs this that the code above needs to be after the chart has been DataBound (had .DataBind() called).
The definition of a line is basically the space between two points. You can't make a line out of one point without it being completely arbitrary.
Once you decide which angle the line should be oriented, just make a 2nd data point that fakes the line however you want it to look. But it actually sounds like you'd prefer a scatter plot, not a line chart. I would suggest changing the chart you use. You will most likely be able to draw lines on the scatter plot as well if needed.
I put this in my question but since it is the answer thought i would put it here also
this is called when there is only 1 point
foreach (Series ser in mainChart.Series)
{
ser.Points.AddY(ser.Points[0].YValues[0]);
}
I had the same problem and I solved it by placing another datapoint with the same values, so it is only to duplicate the same value, when there is only one, and you will place the point. So it would be something similar to this:
this.g.Series[serieID].Points.AddXY(x, y); // <-- Duplicate this line if you only have one value
I have a c# form which is to allow the user to specify a differential equation (dy/dt = -lambda*y) to solve both exactly and approximately (by entering desired values of the intital condition, time step and lambda into textBoxes). Clicking a button calculates the solutions and displays them numerically in boxes as they change over time (using a timer). When the timer finishes, 'Simulation Completed' is displayed in a MessageBox.
At this point, clicking the 'draw graph' button invokes zedGraph to graph the exact and approximate solutions. There are no problems wih calculating and graphing the solutions. The problem is that the label and textBox for timeStep (which I added after adding the zedGraph section) and the 'draw graph' button are superimposed on the graph, partially obscuring it. The textBoxes and labels for lambda and the initial condition were added to the program before the zedGraph part and don't get superimposed.
Is there a way to stop the timeStep label and textBox from being superimposed without having to write the program again, adding the textBox before the zedGraph section?
To summarise: the order in which you add things (at least the way I've done it, if not in general) determines wha happens: adding a textBox before adding the zedGraph section means it doesn't get superimposed on the graph. Add a textBox after adding the zedGraph section and it does get superimposed on the graph. I'm looking for a way o be able to add extra features, having already added the zedGraph section, without them being superimposed on the graph.
You can view 3 screenshots, 2 from before the problem was solved and 1 after here:
https://www.facebook.com/photo.php?fbid=10201376481749572&set=a.10201375193157358.1073741826.1099868090&type=3&theaterset=a.10201375193157358.1073741826.1099868090&type=3&theater
This is a screenshot of the problem:
I just worked out the answer (thanks to God): I just hide the objects I don't want to appear on the graph using the Hide() method at the start of my createGraph() method as follows:
private void CreateGraph(ZedGraphControl zgc)
{
textBox3.Hide();
textBox4.Hide();
label3.Hide();
label5.Hide();
button2.Hide();
Thanks everyone for your input. Quite easy in the end, thankfully... what a relief.
Here's a link to the finished graph:
https://www.facebook.com/photo.php?fbid=10201375420003029&set=a.10201375193157358.1073741826.1099868090&type=3&theater
hey all...
its very hard to explan i hope you understand it and help coz i really need your help guys
the thing is i have to make the user choose the number of matrix with this number i have to create the same number of matrices again and do calculation on each one
like if user matrix 3x3 i have to redo this matrix with different value 3 times
my question is :
1- how can i re do the same number of textboxs over and over .
2- how i can calculate each matrix and get the value
i hope you understand
To create a TextBox dynamically, just new up a new instance of a TextBox, set the properties to decide where it should be shown, and add it to the Controls collection of the container where you want to place it.
As well as adding them to the Controls collection, you could also add the reference to your own collection, which could be, for example a list of lists. That way, when you need to do the calculation you'd just loop through that collection and get the values from each TextBox.
Is it possible to force the display of grid lines on the chart with the dates for the extreme data points?
I've tried almost every configuration of following Chart DateTimeAxis properties: IntervalType, Interval, Minimum and Maximum but I wasn't satisfied with the result.
Setting properties Minimum and Maximum didn't solve the problem.
For instance (IntervalType="Days" , Interval="4" , Minimum="1/1/2010" , Maximum="1/31/2010"):
If I'm lucky I will generate some random data where only one extreme point will have the date with grid line.
Does somebody have an idea how to solve the problem mentioned above?
Edited to add
I added a bounty to this question since I really need a fast solution for this issue.
I am binding a series of specific pairs to my chart and I'd like to display excactly those given DateTime values on the x-axis.
Since these are usually dates like 6/30/11, 6/30/12 and so on, I can't use the Interval/IntervalType properties because adding 1 year or 365 days to 6/30/11 doesn't necessarily result in 6/30/12.
So what I need to do is either disable the "automatic axis label generation" of the DateTime axis or use another axis type.
LinearAxis doesn't work because it expects double values and CategoryAxis is not an option because it displays the axis labels between two tickmarks instead of underneath them.
I am very grateful for any help!
To be perfectly clear, here is what axis labels I need (taken from another chart component):
This is what I get so far with the Silverlight 4 Toolkit:
€: I also opened a thread in the official Silverlight Toolkit Support Forums.
The vertical lines are set where you specify an interval.
There is no vertical line for the data for 1/31/2010 as it does not fall on an interval.