Search code examples
vb.netzedgraphbar-chart

In zedgraph, how to dynamically add/delete bars when Axis.Type=Text


I am using zedgraph to draw bar chart in my vb.net project. The bar base is Y (meaning all bars are horizontal). I have 9 fields for user to choose from, and once a user clicks a field, one corresponding bar will show. Of course, the user can click off the selected field to remove the corresponding bar item. I can do this. The basic idea is to get all bar items and set their visibility according to user's selection. My problems is that I want to have a textlabel next to each bar (this text label is different from legend)so I set the yAxis.Type=text. There are two problems:

1) When I add bars, I still need to specify x and y value. How do I set y value in this case to make sure bar ally perfect with its text?

2) As far as I know, I can add text labels by an array as the last line code shows. But obviously this only works for bar chart with fixed bars. In my case, the number of bars and also the order is changing based on user selection. How can I set text labels?

Dim gpBar As GraphPane
            'bar setting
            gpBar.BarSettings.Base = BarBase.Y

            gpBar.BarSettings.MinBarGap = 0.1
            gpBar.BarSettings.ClusterScaleWidth = 4
            gpBar.BarSettings.Type = BarType.Cluster
            gpBar.YAxis.Type = AxisType.Text
            **gpBar.YAxis.Scale.TextLabels = {"a", "b"}**

Solution

  • A simple but maybe not sufficient solution is to redraw all bars and labels each time a user changes his selection of bars.