Copyright 2005, J4L
Components (http://www.java4less.com)
Go bak to contents
You can use Rchart in your web applications in 2 ways:
You can include the control in a asp.net page so that it creates a chart and the HTML code for it. This approach will create a physical image file on your server. In order to use this approach you must only add the rchart11.dll ( or rchart10.dll if you use .NET 1.0) assembly to your favorite IDE and drop our components on your form. The resulting code will look like this.
<%@ Page Language="C#" %>
<%@ Register TagPrefix="n0" Namespace="J4L.RChart" Assembly="rchart10" %>
<script runat="server">// Insert page code here
//</script>
<html>
<head>
</head>
<body>
<form runat="server">
<n0:ChartWebControl id="ChartWebControl1" runat="server" paramFile="c:\j4l\rchartNET\examples\areaChart_logscale.txt" Width="97px" ImageRetainTime="30" MapName="CHARTMAP" Height="91px" ></n0:ChartWebControl>
<!-- Insert content here -->
</form>
</body>
</html>
You can use RChart in a aspx page to create an image on the fly. Your html page should contain a tag like this:
<img SRC=ChartC.aspx ALT=Chart BORDER=0>
which defines an image that must be read from ChartC.aspx. The ChartC.aspx page must then generate the image in the following way:
[C#]
<%@ Page Language="c#" autoeventwireup="false" Trace="false" Debug="false" %>
<%@ import Namespace="System.Drawing" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Drawing.Imaging" %>
<%@ import Namespace="J4L.RChart" %>
<%@ outputcache duration="100" varybyparam="none" %>
<html>
<head>
</head>
<body>
<pre><%
// define variable
ChartLoader chartLoader= new ChartLoader();// set chart parameters
chartLoader.setParameter("TITLECHART","Sales 2002");
chartLoader.setParameter("XLABEL","Month");
chartLoader.setParameter("YLABEL","Million $");
chartLoader.setParameter("XSCALE_MIN","0");
chartLoader.setParameter("XSCALE_MAX","5.5");
chartLoader.setParameter("YSCALE_MIN","-15");
chartLoader.setParameter("BIG_TICK_INTERVALX","1");
chartLoader.setParameter("BIG_TICK_INTERVALY","10");
chartLoader.setParameter("XAXIS_LABELS","June|July|Aug.|Sept.|Oct.|Nov.|Dec.");
chartLoader.setParameter("CERO_XAXIS","LINE");
chartLoader.setParameter("YAXIS_INTEGER","TRUE");
chartLoader.setParameter("SERIE_1","Products");
chartLoader.setParameter("SERIE_2","Services");
chartLoader.setParameter("SERIE_TYPE_1","BAR");
chartLoader.setParameter("SERIE_TYPE_2","BAR");
chartLoader.setParameter("SERIE_FONT_1","Arial|PLAIN|8");
chartLoader.setParameter("SERIE_FONT_2","Arial|PLAIN|8");
chartLoader.setParameter("SERIE_DATA_1","12|43|50|45|30");
chartLoader.setParameter("SERIE_DATA_2","-10|41|48|39|36");
chartLoader.setParameter("SERIE_BORDER_TYPE_1","RAISED");
chartLoader.setParameter("SERIE_BORDER_TYPE_2","RAISED");
chartLoader.setParameter("SERIE_BAR_STYLE_1","ff00");
chartLoader.setParameter("SERIE_BAR_STYLE_2","ff");
chartLoader.setParameter("BARCHART_BARSPACE","1");
chartLoader.setParameter("LEFT_MARGIN","0.15");
chartLoader.setParameter("CHART_FILL","ffcc00");
chartLoader.setParameter("SERIE_NEGATIVE_STYLE_2","RED");
chartLoader.setParameter("YLABEL_VERTICAL","TRUE");// NOTE: you can also load the parameters from a file using chartLoader.loadFromFile("dataFile.txt",true);
// create chart
Chart chart=chartLoader.buildChart();
chart.setSize(400,400);// create in memory image
Bitmap inMemoryImage = new Bitmap( chart.getSize().Width,chart.getSize().Height);
Graphics g = Graphics.FromImage(inMemoryImage);
// paint chart
chart.paint(g);
MemoryStream tempStream = new MemoryStream();// output image to the memory stream in gif format
inMemoryImage.Save(tempStream,ImageFormat.Gif);Response.ClearContent();
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "image/gif";
Response.BinaryWrite(tempStream.ToArray());
Response.End();
%></pre>
</body>
</html>
[VBNET]
<%@ Page language="VB" AutoEventWireup="false" Trace="false" Debug="false" %>
<%@Import Namespace="System.Drawing" %>
<%@Import Namespace="System.IO" %>
<%@Import Namespace="System.Drawing.Imaging" %>
<%@Import Namespace="J4L.RChart" %>
<%@ OutputCache Duration="100" VaryByParam="none" %>
<%
' define variable
dim chartLoader as ChartLoader = new ChartLoader()' set chart parameters
chartLoader.setParameter("TITLECHART","Sales 2002")
chartLoader.setParameter("XLABEL","Month")
chartLoader.setParameter("YLABEL","Million $")
chartLoader.setParameter("XSCALE_MIN","0")
chartLoader.setParameter("XSCALE_MAX","5.5")
chartLoader.setParameter("YSCALE_MIN","-15")
chartLoader.setParameter("BIG_TICK_INTERVALX","1")
chartLoader.setParameter("BIG_TICK_INTERVALY","10")
chartLoader.setParameter("XAXIS_LABELS","June|July|Aug.|Sept.|Oct.|Nov.|Dec.")
chartLoader.setParameter("CERO_XAXIS","LINE")
chartLoader.setParameter("YAXIS_INTEGER","TRUE")
chartLoader.setParameter("SERIE_1","Products")
chartLoader.setParameter("SERIE_2","Services")
chartLoader.setParameter("SERIE_TYPE_1","BAR")
chartLoader.setParameter("SERIE_TYPE_2","BAR")
chartLoader.setParameter("SERIE_FONT_1","Arial|PLAIN|8")
chartLoader.setParameter("SERIE_FONT_2","Arial|PLAIN|8")
chartLoader.setParameter("SERIE_DATA_1","12|43|50|45|30")
chartLoader.setParameter("SERIE_DATA_2","-10|41|48|39|36")
chartLoader.setParameter("SERIE_BORDER_TYPE_1","RAISED")
chartLoader.setParameter("SERIE_BORDER_TYPE_2","RAISED")
chartLoader.setParameter("SERIE_BAR_STYLE_1","ff00")
chartLoader.setParameter("SERIE_BAR_STYLE_2","ff")
chartLoader.setParameter("BARCHART_BARSPACE","1")
chartLoader.setParameter("LEFT_MARGIN","0.15")
chartLoader.setParameter("CHART_FILL","ffcc00")
chartLoader.setParameter("SERIE_NEGATIVE_STYLE_2","RED")
chartLoader.setParameter("YLABEL_VERTICAL","TRUE")
' NOTE: you can also load the parameters from a file using chartLoader.loadFromFile("dataFile.txt",true)' create chart
dim mychart as Chart
mychart=chartLoader.buildChart()
mychart.setSize(400,400)' create in memory image
dim inMemoryImage as Bitmap= new Bitmap(mychart.getSize().Width,mychart.getSize().Height)
dim g as Graphics = Graphics.FromImage(inMemoryImage)
' paint chart
mychart.paint(g)dim tempStream as MemoryStream = new MemoryStream()
' output image to the memory stream in gif format
inMemoryImage.Save(tempStream,ImageFormat.Gif)
Response.ClearContent()
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "image/gif"
Response.BinaryWrite(tempStream.ToArray())
Response.End()%>