Reputation: 2096
I have following code, original code is: here
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dtTest As DataTable = New DataTable
dtTest.Columns.Add("col1", GetType(Integer))
dtTest.Columns.Add("col2", GetType(Integer))
dtTest.Columns.Add("col3", GetType(String))
dtTest.Rows.Add(0, 1, "S")
dtTest.Rows.Add(0, 1, "H")
dtTest.Rows.Add(80, 1, "C")
dtTest.Rows.Add(43, 2, "S")
dtTest.Rows.Add(11, 2, "H")
dtTest.Rows.Add(55, 2, "C")
dtTest.Rows.Add(30, 3, "S")
dtTest.Rows.Add(85, 3, "H")
dtTest.Rows.Add(53, 3, "C")
dtTest.Rows.Add(55, 4, "S")
dtTest.Rows.Add(55, 4, "H")
dtTest.Rows.Add(11, 4, "C")
Dim dv As DataView = New DataView(dtTest)
dv.Sort = "col2 asc"
Chart1.Series.RemoveAt(0) 'this is just to remove the default Series in a
'VB.NET chart; you may not need this
Chart1.DataBindCrossTable(dv, "col3", "col2", "col1", "Label=col1")
For Each cs As Series In Chart1.Series
cs.ChartType = SeriesChartType.StackedColumn
Next
End Sub
End Class
Code generates chart below.. What I want to know if there is a way not to display a value on column if it is zero, like shown on left most column OR total value on the top of the column would be also good. I found how to do that in excel but did not manage to achieve for this program.
Thanks a lot for help
Upvotes: 2
Views: 6572
Reputation: 54532
You will need to setup Filtering for your Series, I was able to get the result you were looking for by using the Filter(CompareMethod,Double,Series), along with DataManipulator.FilterSetEmptyPoints and DataManipulator.FilterMatchPoints Properties.
Modified Code
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dtTest As DataTable = New DataTable
dtTest.Columns.Add("col1", GetType(Integer))
dtTest.Columns.Add("col2", GetType(Integer))
dtTest.Columns.Add("col3", GetType(String))
dtTest.Rows.Add(0, 1, "S")
dtTest.Rows.Add(0, 1, "H")
dtTest.Rows.Add(80, 1, "C")
dtTest.Rows.Add(43, 2, "S")
dtTest.Rows.Add(11, 2, "H")
dtTest.Rows.Add(55, 2, "C")
dtTest.Rows.Add(30, 3, "S")
dtTest.Rows.Add(85, 3, "H")
dtTest.Rows.Add(53, 3, "C")
dtTest.Rows.Add(55, 4, "S")
dtTest.Rows.Add(55, 4, "H")
dtTest.Rows.Add(11, 4, "C")
Dim dv As DataView = New DataView(dtTest)
dv.Sort = "col2 asc"
Chart1.Series.RemoveAt(0) 'this is just to remove the default Series in a
'VB.NET chart; you may not need this
Chart1.DataManipulator.FilterSetEmptyPoints = True 'Points that match filter will be marked as empty
Chart1.DataManipulator.FilterMatchedPoints = True 'Filter points that match Filter criteria
Chart1.DataBindCrossTable(dv, "col3", "col2", "col1", "Label=col1")
For Each cs As Series In Chart1.Series
Chart1.DataManipulator.Filter(DataVisualization.Charting.CompareMethod.EqualTo, 0, cs) 'Compare if equal to zero
cs.ChartType = SeriesChartType.StackedColumn
Dim dpcp As DataPointCustomProperties = New DataPointCustomProperties
Next
End Sub
Result
Upvotes: 2