OWC11: How to use Custom Drawing with In-Memory Charts

U

UsmanSheikh

Hi,

I am using OWC to create in-memory charts on the server side. My chart is
prety much complete, but I need to change the position of some chart elements
(for example change the position or orientation of Data Labels for series, or
to change the size of legend etc). After reading online and the Black Book, I
have found that the only way to achieve such customiztion is to custom
drawing where you use events like AfterRender, beforeRender and others to
draw stuff on your charts.

The problem is that all the code i have found is for win forms. I need to do
this on web forms and I have no clue of how to use events for something that
is In-Memory. Below is my code, any help or suggestion is greatly appreciated.

Imports Microsoft.Office.Interop.Owc11

Partial Public Class _Default

Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
EventArgs) Handles Button1.Click

Dim chSpace As New ChartSpace
Dim chart As ChChart = chSpace.Charts.Add(0)


'add a new series
series = chart.SeriesCollection.Add()
series.Type = ChartChartTypeEnum.chChartTypeScatterLineMarkers
series.SetData(ChartDimensionsEnum.chDimSeriesNames,
Convert.ToInt32(ChartSpecialDataSourcesEnum.chDataLiteral), "Testing")
series.SetData(ChartDimensionsEnum.chDimXValues,
Convert.ToInt32(ChartSpecialDataSourcesEnum.chDataLiteral), "12,13,15,12")
series.SetData(ChartDimensionsEnum.chDimYValues,
Convert.ToInt32(ChartSpecialDataSourcesEnum.chDataLiteral), "15,16,20,30")

'adding error bars for fake vertical axis
Dim errBarX As ChErrorBars = series.ErrorBarsCollection.Add()
errBarX.Direction = ChartErrorBarDirectionEnum.chErrorBarDirectionX
errBarX.Type = ChartErrorBarTypeEnum.chErrorBarTypeCustom
errBarX.Include = ChartErrorBarIncludeEnum.chErrorBarIncludeBoth
errBarX.Amount = 625 * 2
errBarX.Line.Color = "grey"
errBarX.Line.Weight = 1
errBarX.Line.DashStyle = ChartLineDashStyleEnum.chLineLongDash

'TODO: Move labels to left, remove outer border, change line color
'Styling labels for the fake vertical axis
'Dim label As ChDataLabels = series.DataLabelsCollection.Add()
'label.Position = ChartDataLabelPositionEnum.chLabelPositionLeft
'label.NumberFormat = "mmm-yy"
'label.Item(0).Left = label.Item(0).Left + 15
'series.DataLabelsCollection(0).Position


'Setting up Vertical axis
chart.Axes(0).HasMajorGridlines = False
chart.Axes(0).HasTitle = True
chart.Axes(0).Title.Caption = "Report Date"
chart.Axes(0).MajorTickMarks = ChartTickMarkEnum.chTickMarkNone
chart.Axes(0).HasTickLabels = False

'Setting up Horizontal axis
chart.Axes(1).HasTitle = True
chart.Axes(1).HasMajorGridlines = False
chart.Axes(1).MajorTickMarks = ChartTickMarkEnum.chTickMarkNone
chart.Axes(1).HasTickLabels = False

'Setting up the legend
chart.HasLegend = True
chart.Legend.Position = ChartLegendPositionEnum.chLegendPositionBottom
Dim k As Integer = chart.Legend.LegendEntries.Count
chart.Legend.LegendEntries(k - 1).Visible = False
chart.Legend.LegendEntries(k - 2).Visible = False
chart.PlotArea.SideWall.Border.Color = "Red"


'specify where to save the chart
Dim Path1 As String = "c:\somefilename.gif"
chSpace.ExportPicture(Path1, "GIF", 600, 350)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top