I created an asp.net StackedBar chart with values coming runtime from the database.
Here is how it looks :
Why do my colors not change according to the values on the chart ?
So value 56 should show more red color whereas values 1 should show less red color ? Right now, allthough the values are all different, the width of the colors are all same which does not give the right effect of the graph ?
Code used :
Dim chart As New Chart
chart.ID = DtDistinct.Rows(I)("CourseSisID")
Dim chartareas As New ChartArea
chart.ChartAreas.Add(chartareas)
' chart.DataBindTable(DtRecords.DefaultView)
chart.DataBindCrossTable(DtRecords.DefaultView, "Outcomescore", "ShortName", "Outcomescore", "Label=RecordsPerGroup")
chart.ChartAreas(0).AxisY.Interval = 1
chart.ChartAreas(0).AxisY.LabelStyle.IsEndLabelVisible = True
chart.Palette = ChartColorPalette.None
chart.PaletteCustomColors = New Color() {ColorTranslator.FromHtml("#DF5B59"), ColorTranslator.FromHtml("#E0D773 "), ColorTranslator.FromHtml("#8AAC53"), ColorTranslator.FromHtml("#6A843F")}
chart.ChartAreas(0).AxisX.MajorGrid.Enabled = False
chart.ChartAreas(0).AxisY.MajorGrid.Enabled = False
Dim charttitle As New Title
charttitle.Text = DtDistinct.Rows(I)("CourseSisID")
chart.Titles.Add(charttitle)
For Each cs As Series In chart.Series
cs.ChartType = SeriesChartType.StackedBar
Next
pnlcharts.Controls.Add(chart)
Data :
Any help would be appreciated.
Thank you,
Dee
Change this:
chart.DataBindCrossTable(DtRecords.DefaultView, "Outcomescore", "ShortName", "Outcomescore", "Label=RecordsPerGroup");
with this:
chart.DataBindCrossTable(DtRecords.DefaultView, "OutcomeScore", "ShortName", "RecordsPerGroup", "Label=RecordsPerGroup");
Related
I am trying to add markers on my stacked bar chart programmatically and they do not seem to show up. In reality, I need to show a marker on the average of the datapoint but right now, I cannot even show a simple marker on the chart.
What am I doing wrong ?
Code:
Dim chart As New Chart
chart.ID = DtDistinct.Rows(I)("CourseSisID")
Dim chartareas As New ChartArea
chart.ChartAreas.Add(chartareas)
chart.Series.Clear()
chart.DataBindCrossTable(DtRecords.DefaultView, "Outcomescore", "ShortName", "RecordsPerGroup", "")
chart.ChartAreas(0).AxisY.Interval = 1
chart.ChartAreas(0).AxisY.Enabled = AxisEnabled.False
chart.Palette = ChartColorPalette.None
chart.PaletteCustomColors = New Color() {ColorTranslator.FromHtml("#DF5B59"), ColorTranslator.FromHtml("#E0D773 "), ColorTranslator.FromHtml("#8AAC53"), ColorTranslator.FromHtml("#6A843F")}
chart.ChartAreas(0).AxisX.MajorGrid.Enabled = False
chart.ChartAreas(0).AxisY.MajorGrid.Enabled = False
For Each cs As Series In chart.Series
cs.ChartType = SeriesChartType.StackedBar
cs.Points().FindMaxByValue.MarkerColor = Color.AliceBlue
cs.Points().FindMaxByValue.MarkerSize = 13
cs.Points().FindMaxByValue.MarkerStyle = MarkerStyle.Diamond
Next
pnlcharts.Controls.Add(chart)
Here is an image of what I am trying to do. I know that the above code will not give me the below image but I was trying to find a workaround with the above code, before I realized that markers cannot appear on bar charts.
I would like to see that striped line on the bar chart. The striped line should appear on the calculated average of the points.
So, an another way I could do was to use annotations since markers are not supported by stackedbar charts. I wrote the following code to add an annotation line, but it still does not give me the output I need only because I do not know how to do it for each Y value on the chart.
Here is my code:
Dim chart As New Chart
chart.ID = DtDistinct.Rows(I)("CourseSisID")
Dim chartareas As New ChartArea
chart.ChartAreas.Add(chartareas)
chart.DataBindCrossTable(DtRecords.DefaultView, "OutcomeScore", "ShortName", "RecordsPerGroup", "Label=RecordsPerGroup")
chart.Palette = ChartColorPalette.None
chart.PaletteCustomColors = New Color() {ColorTranslator.FromHtml("#DF5B59"), ColorTranslator.FromHtml("#E0D773 "), ColorTranslator.FromHtml("#8AAC53"), ColorTranslator.FromHtml("#6A843F")}
chart.ChartAreas(0).AxisX.MajorGrid.Enabled = False
chart.ChartAreas(0).AxisY.MajorGrid.Enabled = False
Dim charttitle As New Title
charttitle.Text = DtDistinct.Rows(I)("CourseSisID")
chart.Titles.Add(charttitle)
For Each cs As Series In chart.Series
cs.ChartType = SeriesChartType.StackedBar
Next
Dim ann1 As New VerticalLineAnnotation()
ann1.AxisX = chart.ChartAreas(0).AxisX
ann1.AxisY = chart.ChartAreas(0).AxisY
ann1.IsSizeAlwaysRelative = False
ann1.X = chart.DataManipulator.Statistics.Mean(chart.Series(0).Name)
ann1.IsInfinitive = True
ann1.ClipToChartArea = chart.ChartAreas(0).Name
ann1.LineColor = Color.Coral
ann1.LineWidth = 3
ann1.AnchorX = 1
ann1.AnchorY = 5
chart.Annotations.Add(ann1)
ann1.LineDashStyle = ChartDashStyle.Dash
pnlcharts.Controls.Add(chart)
Here is what I get with the above code:
Here is what I need : Notice how the strip line is at a different value for each bar.
Dim annotation2 As New LineAnnotation()
annotation2.IsSizeAlwaysRelative = False
annotation2.AxisX = chart.ChartAreas(0).AxisX
annotation2.AxisY = chart.ChartAreas(0).AxisY
annotation2.Height = 1
annotation2.Width = 0
annotation2.LineWidth = 1.5
annotation2.StartCap = LineAnchorCapStyle.None
annotation2.EndCap = LineAnchorCapStyle.None
annotation2.AnchorX = AvgVar
annotation2.ToolTip = "Average=" & AvgVar
Select Case row
Case 1
annotation2.AnchorY = 4.5
Case 2
annotation2.AnchorY = 3.5
Case 3
annotation2.AnchorY = 2.5
Case 4
annotation2.AnchorY = 1.5
Case 5
annotation2.AnchorY = 0.5
End Select
' <- your point
annotation2.LineColor = Color.Gray
annotation2.LineDashStyle = ChartDashStyle.Dash
' <- your color
chart.Annotations.Add(annotation2)
I'm trying to add a manually created chart to a placeholder but when i look at the output all i get is a blank.. I am getting the data from a dataset datatable that is the last table in the dataset. I only has two colums "Industry" and "industryTheta" any help is much appreciated. I'm not sure whats wrong here
Dim chrt As New Chart
chrt.ID = "dynChart"
chrt.Height = Unit.Pixel(1000)
chrt.Width = Unit.Pixel(1000)
chrt.BackImageWrapMode = ChartImageWrapMode.Scaled
chrt.BorderlineColor = Color.Black
chrt.ImageLocation = "~/TempImages/ChartPic_#SEQ(300,3)"
chrt.BackGradientStyle = GradientStyle.None
Dim ca As New ChartArea
ca.Name = "IndustryTheta"
ca.AlignmentOrientation = AreaAlignmentOrientations.All
ca.AlignmentStyle = AreaAlignmentStyles.All
ca.Area3DStyle.Enable3D = True
ca.Area3DStyle.LightStyle = LightStyle.Realistic
ca.Area3DStyle.Inclination = 30
ca.BackHatchStyle = ChartHatchStyle.None
chrt.ChartAreas.Add(ca)
Dim sers As New Series
sers.Name = "IndustryName"
sers.ChartType = SeriesChartType.Pie
sers.Label = "#VALX, #PERCENT"
sers.LabelAngle = 90
sers.IsXValueIndexed = True
sers.IsValueShownAsLabel = True
sers.XAxisType = AxisType.Primary
sers.YAxisType = AxisType.Primary
sers.YValuesPerPoint = 1
sers.XValueMember = "Industry"
sers.YValueMembers = "IndustryTheta"
chrt.Series.Add(sers)
For Each dr As DataRow In table.Rows
Dim p As New DataPoint
p.SetValueY(Convert.ToInt32(dr.Item("IndustryTheta")))
p.AxisLabel = dr.Item("Industry")
sers.Points.Add(p)
Next
chrt.DataBind()
dynamicGrids.Controls.Add(chrt)
Most likely your problem is with when you are calling your function in the page life cycle. Please refer to this information to learn more about it.
In order to address dynamic controls in asp.net please refer to this for more information on dynamic controls.
I am binding a datatable to an asp.net chart but want to set the value of the label to a different dataitem (called ResLabelText) than used for the x or y axis. Can this be done? My databinding code is as follows:
chartRes.Series("Month").XValueMember = "MonthName"
chartRes.Series("Month").YValueMembers = "Res"
chartRes.Series("Month").Label = "ResLabelText"
chartRes.Series("Month").ToolTip = "#VALX"
chartRes.DataSource = dt
chartRes.DataBind()
Correct way:
For Each row In dt.Rows
Dim point = New DataPoint()
point.SetValueXY(row.Item("MonthName"), row.Item("Res"))
point.Label = row.Item("LabelRes")
point.ToolTip = row.Item("MonthName")
chartRes.Series("Month").Points.Add(point)
Next
I have a treeview populating from a data set like this
Dim PrSet As New DataSet()
If lblemail.Text.ToString().Equals("ali.saleem#shakarganj.com.pk") Then
PrSet = PDataset("select distinct PEND,to_char(BPV_DTE,'DD MON YYYY') BPV_DTE,BPV_DTE BPV_DTE1,COUNT from chq_dir order by 3 desc")
Else
PrSet = PDataset("select distinct PEND,to_char(BPV_DTE,'DD MON YYYY') BPV_DTE,BPV_DTE BPV_DTE1,COUNT from chq_dte order by 3 desc")
End If
TreeView2.Nodes.Clear()
For Each dr As DataRow In PrSet.Tables(0).Rows
Dim tnParent As New TreeNode()
tnParent.Text = dr("PEND").ToString()
tnParent.Value = dr("BPV_DTE")
tnParent.PopulateOnDemand = True
tnParent.SelectAction = TreeNodeSelectAction.Select
tnParent.ToolTip = tnParent.Text
tnParent.Expand()
TreeView2.Nodes.Add(tnParent)
If dr("COUNT").ToString() = "0" Then
TreeView2.Font.Bold= True
End If
Next dr
There is Column COUNT in which there is 0 in some dates.Problem is that i am trying to bold the treeview where COUNT is 0 but it is not working Any one can give me clear idea to do so.
I have solved My Question Like this
If Not dr("COUNT") = 0 Then
tnParent.Text = "<b>" & dr("PEND").ToString() & "</b>"
End If
I hope I've gethered what you meant by this question...
For Each tn As TreeNode In treeView2.Nodes
If tn.Text = "0" Then
Dim index As Integer
index = tn.Index
treeView2.Nodes(index).NodeFont = New Font(treeView2.Font, FontStyle.Bold)
End If
Next
Apply the style to tnparent and do this before adding the node to parent in treeview, and also from your code it looks like you are changing the fonts to italic not bold.
I'm using NPOI to output excel from Asp.Net. I want to set bold and normal style to my cell but it is working for few cell and not for remaining cell.Please have look on following example:
Dim hssfworkbook As New HSSFWorkbook()
Dim sheetOne As HSSFSheet = hssfworkbook.CreateSheet("Sheet1")
hssfworkbook.CreateSheet("Sheet2")
hssfworkbook.CreateSheet("Sheet3")
Dim cellStyle As HSSFCellStyle = hssfworkbook.CreateCellStyle
cellStyle.Alignment = HSSFCellStyle.ALIGN_CENTER
Dim font As HSSFFont = _hssfworkbook.CreateFont()
font.Boldweight = HSSFFont.BOLDWEIGHT_BOLD
cellStyle.SetFont(font)
For i = 0 To 9 Step 1
'I want to add cell style to these cells
If i Mod 2 = 0 Then
Sheet1.CreateRow(i).CreateCell(1).SetCellValue(i)
font.Boldweight = HSSFFont.BOLDWEIGHT_BOLD
cellStyle.SetFont(font)
Sheet1.GetRow(i).GetCell(1).CellStyle = cellStyle
Else
Sheet1.CreateRow(i).CreateCell(1).SetCellValue(i)
font.Boldweight = HSSFFont.BOLDWEIGHT_NORMAL
cellStyle.SetFont(font)
Sheet1.GetRow(i).GetCell(1).CellStyle = cellStyle
End If
Next
Actually code is working fine but i don't know the particular situation from where and why its stops working for remaining few rows. Its not working properly for all cells and from that particular cell the bold and normal property stops working on whole sheet like sheet2 and sheet3.
You have to use multiple styles because a change to a style affects everywhere that style is referenced in the sheet.
Dim hssfworkbook As New HSSFWorkbook()
Dim sheetOne As HSSFSheet = hssfworkbook.CreateSheet("Sheet1")
hssfworkbook.CreateSheet("Sheet2")
hssfworkbook.CreateSheet("Sheet3")
Dim BoldFont As HSSFFont = hssfworkbook.CreateFont()
BoldFont.Boldweight = HSSFFont.BOLDWEIGHT_BOLD
Dim NormalFont As HSSFFont = hssfworkbook.CreateFont()
NormalFont.Boldweight = HSSFFont.BOLDWEIGHT_NORMAL
Dim cellStyleBold As HSSFCellStyle = hssfworkbook.CreateCellStyle()
With cellStyleBold
.setFont(BoldFont)
.Alignment = HSSFCellStyle.ALIGN_CENTER
End With
Dim cellStyleNormal As HSSFCellStyle = hssfworkbook.CreateCellStyle()
With cellStyleNormal
.setFont(NormalFont)
.Alignment = HSSFCellStyle.ALIGN_CENTER
End With
For i - 0 To 9 Step 1
If i Mod 2 = 0 Then
With Sheet1.CreateRow(i).CreateCell(1)
.SetCellValue(i)
.cellStyle = cellStyleBold
End With
Else
With Sheet1.CreateRow(i).CreateCell(1)
.SetCellValue(i)
.cellStyle = cellStyleNormal
End With
End If
Next