Click here to Skip to main content
16,016,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I have a chart in a WinForms project (Windows Forms) and every second data is added. The problem is that I can't find a way to stop the columns from expanding each time data is added. I have searched all the chart properties but I can't find any. They all look the same.

What I have tried:

I tried all the properties, but even in the code it's the same. I tried on Google but they do on Excel so nothing interesting, I'm not working on Excel but on Visual Studio instead.
Posted
Updated 6-Jul-22 3:52am
Comments
Dave Kreskowiak 5-Jul-22 13:38pm    
It depends on the graphing library you're using if you can do this or not. You never said which library you're using.
Le lance Flamer 2022 6-Jul-22 7:57am    
If you want the library from the chart, it is System.Windows.Forms.DataVisualization.Charting (System.Windows.Forms.DataVisualization). Can you tell me more about the "graphing library" because the libraries are
- System.Drawing
- System.Drawing.Drawing2D
- System.Drawing.Imaging
and if you want more, tell me
[no name] 6-Jul-22 0:38am    
Adding live data indefinitely implies zooming out or scrolling at some point. Standard chart features, or implemented using a scroll viewer and / or view box.

1 solution

The DataVisualization.Charting library will always try to fit all data into the available space occupied by the chart control on the form. There is no option for scrolling in any direction.

You'll either have to find a 3rd-party charting library that supports the features you want, or you'll have to create your own. Creating controls requires a lot of planning and a good understanding of how they work.
 
Share this answer
 
Comments
Le lance Flamer 2022 16-Jul-22 6:58am    
I've managed to find a solution to this problem but it's going to take me a while to explain it all.

But I have another question that I really didn't find anything about (also on the charts): How do you change the text of the labels that are displayed by default (I'm not talking about the legends that show which colour is for a thing but the labels that are displayed on the Y axis for example) because the default text is "100" on the Y axis. I need to change it as it has nothing to do with the data I am displaying on it? I don't want to create a new post on the site for this question.

Thank you very much for your reply!
Dave Kreskowiak 16-Jul-22 11:55am    
It looks like every Axis has a CustomLabels property you can use to assign a collection of CustomLabel objects.

Axis.CustomLabels Property (System.Web.UI.DataVisualization.Charting) | Microsoft Docs[^]
Le lance Flamer 2022 19-Jul-22 12:06pm    
I forgot to say that it is System.Windows.Forms.DataVisualization.Charting and not System.Web.UI.DataVisualization.Charting. Sorry. So still thanks you. I searched even more in that and I can't change the text! I found the right axis but I still can't find anywhere in the chart properties to change the labels text.
Dave Kreskowiak 19-Jul-22 12:32pm    
X axis labels are assigned per DataPoint. Look in your chart Series collection and you'll find a Points property. That will be a collection of DataPoint objects, each of which holds a, well, datapoint on your chart. You're looking for the AxisLabel property of each point to set custom labels for each.

DataPoint Class (System.Windows.Forms.DataVisualization.Charting) | Microsoft Docs[^]
Le lance Flamer 2022 21-Jul-22 16:17pm    
Okay, it adds a label but there are some problems:
1. When the label is added, my series are deleted and I can't find anything to fix that.
2. It seems that I can't change it position.
3. It doesn't delete / modify other labels that are by default. The doc that you gave me is okay but they don't tell much about that, even in the "Properties" category in the doc, they don't explain much.

But still thanks for your answer but I think we don't go very far. I'm still searching, but don't worry, you don't do everything, I am still trying but it seems that we can't do very much about that. I don't know if it would be better to ask a new question on the site because people will know what I'm asking because here they don't see the comments.

Really thanks for your answer. I think it is pretty hard to find the answer about that problem so I will ask a new question but you still can answer me in this question.

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