0
votes

I have a chart that has strings for its x axis (a list of names). It's linked to a dynamic array, I have a problem where the graph resizes itself and squeezes 14-15 strings from the array and makes the bar chart small and tiny.

How can I achieve chunky bars and a scroll bar to scroll down to see the rest of the data even when new values are being added to the x-axis at runtime.

Have spent an hour searching with no help! =[

Edit: Setting the PixelPointWidth Property to 300 gave me the width of the bar the way I want to be, but it has bunched the bars so that all the bars of the 4 series are overlapping instead of being side by side. WHere to go from here?

Edit2:

Manipulating the charts height is definitely getting the desired results, the only thing is the bigger the height, the more white space at the top of the chart, whats the fix for that,. and a fix for the Series representations to be "frozen" on scroll.

1
I've never actually used the Chart control so I don't know whether it has something built in but, if not, one option would be to place the Chart inside a Panel and let the Panel resize and provide scrollbars while the Chart remains the same size. - jmcilhinney
After a new item is added to the x axis the chart automatically gets resized - Stavros
I think you would normally do this by calling the AxisScaleView.Zoom Method of the ChartArea's AxisX Property, which would create a scrollable view into the chart data. Having strings for the points' x values complicates things somewhat, but the Series.IsXValueIndexed Property could be useful in that case. - stevec

1 Answers

0
votes

You can set the width of the chart every time you add new data to it:

Dim barWidth = Double.Parse(Chart1.Series(0)("PixelPointWidth"))
Chart1.Width = CInt(nData * barWidth) + 100

where nData is how many points there are and the 100 is some amount to take into account the space needed for the Y-axis labels and the legend.

Place the chart control in a Panel as suggested by jmcilhinney with AutoScroll set to true, and you will get a scrollbar when the width of the chart exceeds the width of the panel.

If you want the chart to show the latest added data, you can set the horizontal scroll position after setting the width of the chart:

Panel1.HorizontalScroll.Value = Panel1.HorizontalScroll.Maximum