You create a tree map chart by creating an instance of the NTreeMapChart class, which holds an instance to the tree map root node accessible from RootTreeMapNode property. The tree hierarchy is then created by adding instances of the NGroupTreeMapNode and NValueTreeMapNode classes that represent a collection of nodes and leaf node respectively. The following code shows how to create the simple tree map from the picture above:
C# |
Copy Code
|
---|---|
// remove the default panels nChartControl1.Panels.Clear(); nChartControl1.BackgroundStyle.FrameStyle.Visible = false; // create a tree map chart NTreeMapChart treeMapChart = new NTreeMapChart(); treeMapChart.DockMode = PanelDockMode.Fill; nChartControl1.Panels.Add(treeMapChart); // add some group and value nodes NGroupTreeMapNode technologyNode = new NGroupTreeMapNode("Technology"); technologyNode.Margins = new NMarginsL(2); technologyNode.StrokeStyle = new NStrokeStyle(2, Color.Black); treeMapChart.RootTreeMapNode.ChildNodes.Add(technologyNode); technologyNode.ChildNodes.Add(new NValueTreeMapNode(656.4, -1.16, "Software Programming", new NColorFillStyle(Color.FromArgb(129, 200, 0)))); technologyNode.ChildNodes.Add(new NValueTreeMapNode(619.9, 1.22, "Semiconductors", new NColorFillStyle(Color.FromArgb(255, 204, 0)))); technologyNode.ChildNodes.Add(new NValueTreeMapNode(535.9, -0.1, "Communications Equipment", new NColorFillStyle(Color.FromArgb(241, 85, 0)))); technologyNode.ChildNodes.Add(new NValueTreeMapNode(277.1, 0.06, "Computer Hardware", new NColorFillStyle(Color.FromArgb(126, 0, 255)))); NGroupTreeMapNode healthcareNode = new NGroupTreeMapNode("Healthcare"); healthcareNode.Margins = new NMarginsL(2); healthcareNode.StrokeStyle = new NStrokeStyle(2, Color.Black); treeMapChart.RootTreeMapNode.ChildNodes.Add(healthcareNode); healthcareNode.ChildNodes.Add(new NValueTreeMapNode(446, -0.45, "Major Drugs", new NColorFillStyle(Color.FromArgb(129, 200, 0)))); healthcareNode.ChildNodes.Add(new NValueTreeMapNode(593.3, -1.77, "Biotechnology Drugs", new NColorFillStyle(Color.FromArgb(255, 204, 0)))); healthcareNode.ChildNodes.Add(new NValueTreeMapNode(325.4, -0.67, "Medical Equipment Supplies", new NColorFillStyle(Color.FromArgb(241, 85, 0)))); |
Visual Basis |
Copy Code
|
---|---|
' remove the default panels NChartControl1.Panels.Clear() NChartControl1.BackgroundStyle.FrameStyle.Visible = False NChartControl1.Width = 420 NChartControl1.Height = 320 ' create a tree map chart Dim treeMapChart As New NTreeMapChart() treeMapChart.DockMode = PanelDockMode.Fill NChartControl1.Panels.Add(treeMapChart) ' add some group and value nodes Dim technologyNode As New NGroupTreeMapNode("Technology") technologyNode.Margins = New NMarginsL(2) technologyNode.StrokeStyle = New NStrokeStyle(2, Color.Black) treeMapChart.RootTreeMapNode.ChildNodes.Add(technologyNode) technologyNode.ChildNodes.Add(New NValueTreeMapNode(656.4, -1.16, "Software Programming", New NColorFillStyle(Color.FromArgb(129, 200, 0)))) technologyNode.ChildNodes.Add(New NValueTreeMapNode(619.9, 1.22, "Semiconductors", New NColorFillStyle(Color.FromArgb(255, 204, 0)))) technologyNode.ChildNodes.Add(New NValueTreeMapNode(535.9, -0.1, "Communications Equipment", New NColorFillStyle(Color.FromArgb(241, 85, 0)))) technologyNode.ChildNodes.Add(New NValueTreeMapNode(277.1, 0.06, "Computer Hardware", New NColorFillStyle(Color.FromArgb(126, 0, 255)))) Dim healthcareNode As New NGroupTreeMapNode("Healthcare") healthcareNode.Margins = New NMarginsL(2) healthcareNode.StrokeStyle = New NStrokeStyle(2, Color.Black) treeMapChart.RootTreeMapNode.ChildNodes.Add(healthcareNode) healthcareNode.ChildNodes.Add(New NValueTreeMapNode(446, -0.45, "Major Drugs", New NColorFillStyle(Color.FromArgb(129, 200, 0)))) healthcareNode.ChildNodes.Add(New NValueTreeMapNode(593.3, -1.77, "Biotechnology Drugs", New NColorFillStyle(Color.FromArgb(255, 204, 0)))) healthcareNode.ChildNodes.Add(New NValueTreeMapNode(325.4, -0.67, "Medical Equipment Supplies", New NColorFillStyle(Color.FromArgb(241, 85, 0)))) |