ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  tool tip problem with real time chart
Posted by Salman on Sep-05-2006 14:59
Attachments:
please see the attached document.
ChartProblems.doc
ChartProblems.doc

37.50 Kb

  Re: tool tip problem with real time chart
Posted by Salman on Sep-05-2006 15:04
one more thing i am using chart ver 4.1 and working on asp.net
thanks

  Re: tool tip problem with real time chart
Posted by Peter Kwan on Sep-06-2006 01:26
Attachments:
Hi Salman,

I guess you are using the standard "realtimechart.aspx" sample code that comes with ChartDirector. This sample code uses the "streamUpdate" method to stream a real time chart to the browser (somewhat like sending a "movie" to the browser).

As explained in "ChartDirector Documentation/Realtime Charts/Realtime Chart Demonstration (Web)", the "streamUpdate" method does not support updating the image map (so no image map should be used). To update the image map as well, one needs to use the AJAX based "partialUpdate" method.

I have attached a sample code using the partialUpdate method for your reference, in which both the chart image and the image maps are updated. Basically, it is the same as the streamUpdate code, except the streamUpdate/StreamChart/IsStreamRequest are replaced by the corresponding partialUpdate methods (partialUpdate/PartialUpdateChart/IsPartialUpdateRequest).

Hope this can help.

Regards
Peter Kwan
realtimedemo.aspx
<%@ Page Language="C#" Debug="true" %>
<%@ Import Namespace="ChartDirector" %>
<%@ Register TagPrefix="chart" Namespace="ChartDirector" Assembly="netchartdir" %>
<script runat="server">

//
// Draw the chart
//
private void drawChart(WebChartViewer viewer)
{
    //
    // Data to draw the chart. In this demo, the data buffer will be filled by a random data
    // generator. In real life, the data is probably stored in a buffer (eg. a database table, a
    // text file, or some global memory) and updated by other means.
    //

    // We use a data buffer to emulate the last 240 samples.
    int sampleSize = 240;
    double[] dataSeries1 = new double[sampleSize];
    double[] dataSeries2 = new double[sampleSize];
    double[] dataSeries3 = new double[sampleSize];
    DateTime[] timeStamps = new DateTime[sampleSize];

    // Our pseudo random number generator
    DateTime firstDate = DateTime.Now.AddSeconds(-timeStamps.Length);
    for(int i = 0; i < timeStamps.Length; ++i) {
        timeStamps[i] = firstDate.AddSeconds(i);
        double p = timeStamps[i].Ticks / 10000000;
        dataSeries1[i] = Math.Cos(p * 7 * 18463) * 10 + 1 / (Math.Cos(p) * Math.Cos(p) + 0.01) + 20;
        dataSeries2[i] = 100 * Math.Sin(p / 27.7) * Math.Sin(p / 10.1) + 150;
        dataSeries3[i] = 100 * Math.Cos(p / 6.7) * Math.Cos(p / 11.9) + 150;
    }

    // Create an XYChart object 600 x 270 pixels in size, with light grey (f4f4f4) background, black
    // (000000) border, 1 pixel raised effect, and with a rounded frame.
    XYChart c = new XYChart(600, 270, 0xf4f4f4, 0x000000, 0);
    c.setRoundedFrame();

    // Set the plotarea at (55, 62) and of size 520 x 175 pixels. Use white (ffffff) background.
    // Enable both horizontal and vertical grids by setting their colors to grey (cccccc). Set
    // clipping mode to clip the data lines to the plot area.
    c.setPlotArea(55, 62, 520, 175, 0xffffff, -1, -1, 0xcccccc, 0xcccccc);
    c.setClipping();

    // Add a title to the chart using 15 pts Times New Roman Bold Italic font, with a light grey
    // (dddddd) background, black (000000) border, and a glass like raised effect.
    c.addTitle("Zooming and Scrolling Demonstration", "Times New Roman Bold Italic", 15
        ).setBackground(0xdddddd, 0x000000, Chart.glassEffect());

    // Add a legend box at the top of the plot area with 9pts Arial Bold font. We set the legend box
    // to the same width as the plot area and use grid layout (as opposed to flow or top/down
    // layout). This distributes the 3 legend icons evenly on top of the plot area.
    LegendBox b = c.addLegend2(55, 33, 3, "Arial Bold", 9);
    b.setBackground(Chart.Transparent, Chart.Transparent);
    b.setWidth(520);

    // Configure the y-axis with a 10pts Arial Bold axis title
    c.yAxis().setTitle("Price (USD)", "Arial Bold", 10);

    // Configure the x-axis to auto-scale with at least 75 pixels between major tick and 15 pixels
    // between minor ticks. This shows more minor grid lines on the chart.
    c.xAxis().setTickDensity(75, 15);

    // Set the axes width to 2 pixels
    c.xAxis().setWidth(2);
    c.yAxis().setWidth(2);

    // Set the x-axis label format
    c.xAxis().setLabelFormat("{value|hh:nn:ss}");

    // Create a line layer to plot the lines
    LineLayer layer = c.addLineLayer2();

    // The x-coordinates are the timeStamps.
    layer.setXData(timeStamps);

    // The 3 data series are used to draw 3 lines. Here we put the latest data values as part of the
    // data set name, so you can see them updated in the legend box.
    layer.addDataSet(dataSeries1, 0xff0000, c.formatValue(dataSeries1[dataSeries1.Length - 1],
        "Software: <*bgColor=FFCCCC*> {value|2} "));
    layer.addDataSet(dataSeries2, 0x00cc00, c.formatValue(dataSeries2[dataSeries2.Length - 1],
        "Hardware: <*bgColor=CCFFCC*> {value|2} "));
    layer.addDataSet(dataSeries3, 0x0000ff, c.formatValue(dataSeries3[dataSeries3.Length - 1],
        "Services: <*bgColor=CCCCFF*> {value|2} "));

    // output the chart
    WebChartViewer1.Image = c.makeWebImage(Chart.PNG);
    WebChartViewer1.ImageMap = c.getHTMLImageMap("", "", "title='x={x|hh:nn:ss}, y={value|2}'");
}

//
// Page Load event handler
//
protected void Page_Load(object sender, EventArgs e)
{
    // Draw chart using the most update data
    drawChart(WebChartViewer1);

    // If is streaming request, output the chart immediately and terminate the page
    if (WebChartViewer.IsPartialUpdateRequest(Page)) {
        WebChartViewer1.PartialUpdateChart();
    }
}

</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>ChartDirector Realtime Chart Demonstration</title>
    <script type="text/javascript" src="cdjcv.js"></script>
</head>
<body style="margin:0px">
<table cellspacing="0" cellpadding="0" border="0">
    <tr>
        <td align="right" colspan="2" style="background:#000088">
            <div style="padding-bottom:2px; padding-right:3px; font-weight:bold; font-size:10pt; font-style:italic; font-family:Arial;">
                <a style="color:#FFFF00; text-decoration:none" href="http://www.advsofteng.com/">Advanced Software Engineering</a>
            </div>
        </td>
    </tr>
    <tr valign="top">
        <td style="width:150px; background:#c0c0ff; border-left:black 1px solid; border-right:black 1px solid; border-bottom:black 1px solid;">
            <br /><br />
            <div style="padding:10px; font-size:9pt; font-family:Verdana">
                <b>Update Period</b><br />
                <select id="UpdatePeriod" style="width:130px">
                    <option value="5">5 seconds</option>
                    <option value="10" selected="selected">10 seconds</option>
                    <option value="20">20 seconds</option>
                    <option value="30">30 seconds</option>
                    <option value="60">60 seconds</option>
                </select>
            </div>
            <div style="padding:10px; font-size:9pt; font-family:Verdana">
                <b>Time Remaining</b><br />
                <div style="width:130px; border:#888888 1px inset;">
                    <div style="margin:3px" id="TimeRemaining">&nbsp;</div>
                </div>
            </div>
        </td>
        <td>
            <div style="font-weight:bold; font-size:20pt; margin:5px 0px 0px 5px; font-family:Arial">
                ChartDirector Realtime Chart Demonstration
            </div>
            <hr style="border:solid 1px #000080" />
            <div style="padding:0px 5px 0px 10px">
                <chart:webchartviewer id="WebChartViewer1" runat="server" />
            </div>
        </td>
    </tr>
</table>
<script type="text/javascript">
// The followings is executed once every second
function updateDisplay()
{
    // Utility to get an object by id that works with most browsers
    var getObj = function(id) {    return document.getElementById ? document.getElementById(id) : document.all[id]; }

    // Get the configured update period
    var updatePeriodObj = getObj("UpdatePeriod");
    var updatePeriod = parseInt(updatePeriodObj.value);

    // Subtract 1 second for the remaining time - reload the counter if remaining time is 0
    if (!updatePeriodObj.timeLeft || (updatePeriodObj.timeLeft <= 0))
        updatePeriodObj.timeLeft = updatePeriod - 1;
    else
        updatePeriodObj.timeLeft = Math.min(updatePeriod, updatePeriodObj.timeLeft) - 1;

    // Update the chart if configured time has elasped
    if ((updatePeriodObj.timeLeft <= 0) && window.JsChartViewer)
        JsChartViewer.get('<%=WebChartViewer1.ClientID%>').partialUpdate();

    // Update the display to show remaining time
    getObj("TimeRemaining").innerHTML = updatePeriodObj.timeLeft + ((updatePeriodObj.timeLeft > 1) ? " seconds" : " second");
}
JsChartViewer.updatingMsg = '';
window.setInterval("updateDisplay()", 1000);
</script>
</body>
</html>