Tutorial 4: Spline stacked area chart (ASP.NET web projects)
« on: February 04, 2016, 12:50:43 PM »
This example illustrates how to render a chart on a web browser. No temporary files are involved (all processing is done in memory on the fly).

You need two web forms. The first form will contain the chart. Insert the following HTML tag wherever you want the chart to be drawn:

Code: [Select]
<img src="chart1.aspx"/>
The second web form ("chart1.aspx") will render the chart. The output is "captured" by the HTML tag of the first web form.

Steps:
1. Create a new ASP.NET application project (VB.NET)
2. Add a web page (default.aspx) to the web project and insert the <img src="chart1.aspx"> between <body> and </body> tags.
3. Add a reference to Crossing Charts Library and to System.Windows.Forms (this one is necessary for the library to operate on web environments)
4. Add a second web page (chart1.aspx) to the web project project and copy&paste the following code in the Page_Load event:

Code: [Select]
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
   Dim oGraph As New CrossingChartsLibrary.CrossingCharts
   ' Get some random values ...
   Dim arrSeries(2) As ArrayList
   For k As Integer = 0 To UBound(arrSeries)
      arrSeries(k) = New ArrayList
      For j As Integer = 0 To 5
         arrSeries(k).Add(Rnd() * 500)
      Next
   Next
   ' Assign properties to Crossing Charts control ...
   With oGraph
      .AutoRefresh = False ' This prevents unnecessary redraws

      .Series = arrSeries  ' Assign previous random values
      .Title = "3D Spline Stacked Area" ' Title of the chart
      .Style = CrossingChartsLibrary.STYLE2D3D.STYLE3D_SPLINE_STACKED_AREA
      .Width = 500         ' Width of the output bitmap
      .Height = 350        ' Height of the output bitmap
      .ShowValues = False  ' Don't show values over chart
      .BackColor = Drawing.Color.LightGoldenrodYellow
      .BackStyle = _
          CrossingChartsLibrary.STYLEBACKGROUND.STYLEBACKGROUND_GRADIENT
      .WallStyle = CrossingChartsLibrary.STYLEWALLS.STYLEWALLS_VISIBLE
      .RefreshChart()      ' Draw the chart on internal buffer
   End With
   ' Now, let's output the drawn chart...
   ' Change the response headers to output a JPEG image.
   Response.Clear()
   Response.ContentType = "image/jpeg"
   ' Write the image to the response stream in JPEG format.
   oGraph.Image.Save(Response.OutputStream, _
                     System.Drawing.Imaging.ImageFormat.Jpeg)
   ' Free memory
   oGraph.Dispose()
End Sub

Results:
« Last Edit: February 16, 2016, 08:54:12 AM by CrossingCharts »