Page 1 of 1

TeeChart for .NET 2015 4.1.2015.12160 - Events not invoked

Posted: Fri Aug 30, 2024 8:22 am
by 15670607
Hi,

I have been unable to get the webchart events to fire when clicking. I've created a simple asp.net solution on github to illustrate.
I've read and followed the documentation at https://steema.com/docs/teechart/net/tu ... ations.htm
to the tee.
The only event that seems to be invoked is Afterdraw. I can't get ClickBackground, ClickSeries or ClickLegend to trigger.

Default.aspx

Code: Select all

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TeeChartEventTest._Default" %>

<%@ Register Assembly="TeeChart" Namespace="Steema.TeeChart.Web" TagPrefix="tchart" %>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">

    <div class="row">
        <div class="col-md-12">
            <h2>TeeChart Demo</h2>
            <p>
                <tchart:WebChart ID="WebChart1" AutoPostback="True" TempChart="Httphandler" runat="server" OnAfterDraw="WebChart1_AfterDraw" OnClickBackground="WebChart1_ClickBackground" OnClickSeries="WebChart1_ClickSeries" GetChartFile="" Height="300px" Width="400px" OnClickLegend="WebChart1_ClickLegend" />
            </p>
        </div>
    </div>

</asp:Content>
Code behind:

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using Steema.TeeChart.Styles;
using System.Drawing;

namespace TeeChartEventTest
{
    public partial class _Default : Page
    {
        private int clickedX;
        private int clickedY;
        private string msgText;

        protected void Page_Load(object sender, EventArgs e)
        {
            Steema.TeeChart.Chart ch1 = WebChart1.Chart;
            MemoryStream tmpChart = new MemoryStream();

            if (Session["ch3"] == null)
            {
                //setup Chart
                if (ch1.Series.Count < 2)
                {
                    ch1.Series.Add(new Steema.TeeChart.Styles.Points());
                    ch1.Series.Add(new Steema.TeeChart.Styles.Points());
                }

                //this.seriesHotspot1 = new Steema.TeeChart.Tools.SeriesHotspot(ch1);

                ((Points)ch1.Series[0]).Pointer.Pen.Visible = false;
                ((Points)ch1.Series[1]).Pointer.Pen.Color = Color.FromArgb(79, 79, 255);

                ch1.Series[0].Color = Color.FromArgb(255, 199, 26);
                ch1.Series[1].Color = Color.FromArgb(106, 106, 255);

                ch1.Series[0].FillSampleValues(6);
                ch1.Series[1].FillSampleValues(6);
                //export Chart to a MemoryStream template
                ch1.Export.Template.Save(tmpChart);
                //save template to a Session variable
                Session.Add("ch3", tmpChart);
            }
            else
            {
                //retrieve the session stored Chart
                tmpChart = (MemoryStream)Session["ch3"];
                //set the Stream position to 0 as the last read/write
                //will have moved the position to the end of the stream
                tmpChart.Position = 0;
                //import saved Chart
                ch1.Import.Template.Load(tmpChart);
            }
        }

        // Huh???
        protected void WebChart1_ClickBackground(object sender, ImageClickEventArgs e)
        {
            Steema.TeeChart.Chart tChart = ((Steema.TeeChart.Web.WebChart)sender).Chart;
            //int index = WebChart2.Chart.Legend.Clicked(e.X, e.Y);

            //event triggered when any point on the Chart is clicked. If the ClickSeries event is active
            //it will take precedence when a Series is clicked.
            clickedX = e.X;
            clickedY = e.Y;
            msgText = "Clicked background\n\rX:" + tChart.Axes.Bottom.CalcPosPoint(clickedX).ToString("#0.00")
               + ", Y:" + tChart.Axes.Left.CalcPosPoint(clickedY).ToString("#0.00");
        }

        protected void WebChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            if (clickedX > 0)
            {
                g.Font.Bold = true;
                g.Font.Color = Color.Blue;
                g.TextOut(clickedX, clickedY, msgText);
            }
        }

        // HUH??
        protected void WebChart1_ClickSeries(object sender, Series s, int valueIndex, EventArgs e)
        {
            Steema.TeeChart.Chart tChart = ((Steema.TeeChart.Web.WebChart)sender).Chart;

            clickedX = s.CalcXPos(valueIndex);
            clickedY = s.CalcYPos(valueIndex);
            msgText = "Series: " + tChart.Series.IndexOf(s).ToString() + "\n\rValue: " + s.YValues[valueIndex].ToString("#0.00");
        }

        // HUH??
        protected void WebChart1_ClickLegend(object sender, ImageClickEventArgs e)
        {

        }
    }
}
What am I missing?
The full code can be found at https://github.com/burningza/TeechartEventTest

Please help

Re: TeeChart for .NET 2015 4.1.2015.12160 - Events not invoked

Posted: Mon Sep 02, 2024 7:25 am
by Marc
Hello,

We are checking what differences there may be between your test project and the Steema example project.

Regards,
Marc Meumann

Re: TeeChart for .NET 2015 4.1.2015.12160 - Events not invoked

Posted: Fri Sep 06, 2024 3:20 pm
by Marc
Hello,

The problem is solvable and seems to lie with the code in the the Page_Load method, perhaps because of an invalid mix of ch* session variable names.

I copied the code in from a similar method from the TeeChart, WebChart demo, zoom demo to the page_load method, changing Point Series to Bar and it worked correctly, responding to the clicks. I'll try and hone in on the exact issue when I get a moment, you may find it more quickly.

Regards,
Marc