Jump to content

Cannot assign new Title to streams of a UniChart


Woutero

Recommended Posts

Sir

I'm using UniGUI Complete Professional V1.90.0.1560 in RAD C++ Builder 10.4 Update 2.

I'm getting an Ajax error when trying to assign a new title to a stream of a UniChart.

I have the following procedure:

void __fastcall TMainForm::SetNewTitle(TUniChart *ThisChart, int StreamNo)
{
   UnicodeString NewTitle;

     NewTitle = "New Title";
     if (StreamNo==0)
       ThisChart->JSInterface->JSCall((UnicodeString)L"chart.series[0].setTitle",ARRAYOFCONST((NewTitle)));
     if (StreamNo==1)
       ThisChart->JSInterface->JSCall((UnicodeString)L"chart.series[1].setTitle",ARRAYOFCONST((NewTitle)));
     if (StreamNo==2)
       ThisChart->JSInterface->JSCall((UnicodeString)L"chart.series[2].setTitle",ARRAYOFCONST((NewTitle)));

}

As long as the UniChart has 3 UniLineSeries, everything works fine when I call

SetNewTitle(UniChart,0);
SetNewTitle(UniChart,1);
SetNewTitle(UniChart,2);

But as soon as I use 3 UniBarSeries, UniAreaSeries or any other series on the UniChart, then calling SetNewTitle for all 3 series gives an Ajax error:

"Cannot read properties of undefined (reading 'SetTitle')"

The easiest fix would be to allow us to set the Title property for each Series in the SeriesList:

UniChart->SeriesList->Series[0]->Title = "New Title";
UniChart->SeriesList->Series[1]->Title = "New Title";
UniChart->SeriesList->Series[2]->Title = "New Title";

Then we don't even have to use the JSCall which is not working for UniBarSeries, UniAreaSeries and other series in C++Builder.

By the way, I have to tell you that the uniGUI framework is most amazing. I only have the greatest respect for your work, you are a genius!!

If only we could fix this bug then I will  be a vey happy customer…

 

 

  • Like 1
Link to comment
Share on other sites

Sherzod

I also tried "chart.getSeries()[0].setTitle"...
which gave the error:
Cannot read properties of undefined (reading 'setTitle')

and
"chart.series.getAt(0).setTitle"...
gave the error:
chart.series.getAt is not a function

Link to comment
Share on other sites

Sherzod

I tested in Delphi 10.4.2

 ThisChart.JSInterface.JSCall('chart.series[0].setTitle',[NewTitle]);
gives runtime error:
Cannot read properties of undefined (reading 'setTitle')

 ThisChart.JSInterface.JSCall('chart.getSeries()[0].setTitle',[NewTitle]);
gives same error.

ThisChart.JSInterface.JSCall('chart.series.getAt(0).setTitle',[NewTitle]);
gives runtime error:
chart.series.getAt is not a function

Delphi also does not allow
UniChart1.SeriesList.Series[0].Title := 'New Title';

giving compiling error:
Cannot access protected symbol TUniChartSeries

Link to comment
Share on other sites

Sherzod

Yes, the SetTitle() procedure works in Delphi, but I cannot get the SetTitle procedure to work in C++.

This is the code that I have used:

#pragma link "uniStrUtils"

void __fastcall TMainForm::SetTitle(TUniBarSeries *AUniBarSeries, UnicodeString ATitle)
{
  int I;
  UnicodeString Titles;

  Titles = "";
  if ((ATitle!="")  && (AUniBarSeries->Title!=ATitle))
  {
    AUniBarSeries->Title = ATitle;
    for (I=0; I<AUniBarSeries->Parent->SeriesList->Count; I++)
      Titles = Titles + """ + ((TUniBarSeries)AUniBarSeries->Parent->SeriesList[I])->Title + "",";

      Titles = RemoveTrailingChar(Titles, ',');

      AUniBarSeries->Parent->JSInterface->JSCall("chart.series[0].setTitle",ARRAYOFCONST((Titles)));
  }

}

By the way, I have added the line 
Titles = "" because Titles was never initialized before the loop.
I tried both String and UnicodeString.

How should we change SetTitle() to work in C++?

Link to comment
Share on other sites

Can you try this code?:

void __fastcall TMainForm::SetTitle(TUniBarSeries *AUniSeries, UnicodeString ATitle)
{
    int I;
    UnicodeString Titles = "";

    if (ATitle != "" && AUniSeries->Title != ATitle)
    {
        AUniSeries->Title = ATitle;
        for (I = 0; I < AUniSeries->Parent->SeriesList->Count; ++I)
        {
            TUniBarSeries *Series = dynamic_cast<TUniBarSeries *>(AUniSeries->Parent->SeriesList->Items[I]);
            if (Series)
                Titles = Titles + "\"" + Series->Title + "\",";
        }

        Titles = RemoveTrailingChar(Titles, ',');
        TJSArray *JSArrayResult = AUniSeries->Parent->JSInterface->JSArray(Titles);
        AUniSeries->Parent->JSInterface->JSCall("chart.series[0].setTitle", JSArrayResult);
    }
}

 

Link to comment
Share on other sites

Sherzod
Thanks!
Which units should I include to compile?
C++ Builder 10.4 (target Windows 64bit) throws error at dynamic_cast: 'void' is not a class
Also does not recognize TJSArray when I include "System.JSON.hpp"

Link to comment
Share on other sites

11 hours ago, Woutero said:

Which units should I include to compile?
C++ Builder 10.4 (target Windows 64bit) throws error at dynamic_cast: 'void' is not a class
Also does not recognize TJSArray when I include "System.JSON.hpp"

Hello,

Sorry, I'm not good at C++Builder.
I asked a question to chatGPT 🙂 and I don't have a way to test the code at the moment.

Try also this code:

void __fastcall TMainForm::SetTitle(TUniBarSeries *AUniSeries, UnicodeString ATitle)
{
    int I;
    UnicodeString Titles = "";

    if (ATitle != "" && AUniSeries->Title != ATitle)
    {
        AUniSeries->Title = ATitle;
        for (I = 0; I < AUniSeries->Parent->SeriesList->Count; ++I)
        {
            TUniBarSeries *Series = AUniSeries->Parent->SeriesList->Items[I];
            TUniBarSeries *BarSeries = (TUniBarSeries*)Series; // Explicit casting, Make sure all types are the same...
            Titles = Titles + "\"" + BarSeries->Title + "\",";
        }

        Titles = RemoveTrailingChar(Titles, ',');
        AUniSeries->Parent->JSInterface->JSCall("chart.series[0].setTitle", AUniSeries->Parent->JSInterface->JSArray(Titles));
    }
}

 

Link to comment
Share on other sites

Sorry, still not compiling.

TUniBarSeries *Series = AUniSeries->Parent->SeriesList->Items[I];

throws error: cannot initialize a variable of type 'Unichart::TUniBarSeries *' with an rvalue of type 'void *'

AUniSeries->Parent->JSInterface->JSCall("chart.series[0].setTitle", AUniSeries->Parent->JSInterface->JSArray(Titles));

throws error: no matching member function for call to 'JSCall'

Link to comment
Share on other sites

Anyone else with suggestions?

We need to translate the following line of Delphi code to C++:

for I := 0 to AUniBarSeries.Parent.SeriesList.Count-1 do
      Titles := Titles + '"' + (AUniBarSeries.Parent.SeriesList[I] as TUniBarSeries).Title + '",';

Currently we have

for (I = 0; I < AUniSeries->Parent->SeriesList->Count; ++I)
        {
            TUniBarSeries *Series = AUniSeries->Parent->SeriesList->Items[I];
            TUniBarSeries *BarSeries = (TUniBarSeries*)Series; // Explicit casting, Make sure all types are the same...
            Titles = Titles + "\"" + BarSeries->Title + "\",";
        }

which throws na error:
cannot initialize a variable of type 'Unichart::TUniBarSeries *' with an rvalue of type 'void *'

Link to comment
Share on other sites

Did you mean:

  Title1 = UniChart->SeriesList->Series[0]->Title;
  Title2 = UniChart->SeriesList->Series[1]->Title;
  Title3 = UniChart->SeriesList->Series[2]->Title;


This is not allowed, gives error: 'Title' is a protected member of 'UniChart::TUniChartSeries'

 

Link to comment
Share on other sites

Sherzod

I believe it should work.

The following C++ code works perfectly for UniLineSeries, but does not work for UniBarSeries, UniAreaSeries and other series:


UnicodeString NewTitle;

     NewTitle = "New Title";
     if (StreamNo==0)
       ThisChart->JSInterface->JSCall((UnicodeString)L"chart.series[0].setTitle",ARRAYOFCONST((NewTitle)));
     if (StreamNo==1)
       ThisChart->JSInterface->JSCall((UnicodeString)L"chart.series[1].setTitle",ARRAYOFCONST((NewTitle)));
     if (StreamNo==2)
       ThisChart->JSInterface->JSCall((UnicodeString)L"chart.series[2].setTitle",ARRAYOFCONST((NewTitle)));


When the same code is run on UniBarSeries and UniAreaSeries then it generates an Ajax error:
Cannot read properties of undefined (reading 'setTitle')

Why can't UniGUI simply allow:

UniChart->SeriesList->Series[0]->Title = "New Title";
UniChart->SeriesList->Series[1]->Title = "New Title";
UniChart->SeriesList->Series[2]->Title = "New Title";

Link to comment
Share on other sites

33 minutes ago, Woutero said:

When the same code is run on UniBarSeries

Because for them there is only one series...

 

35 minutes ago, Woutero said:

Why can't UniGUI simply allow:

UniChart->SeriesList->Series[0]->Title = "New Title";
UniChart->SeriesList->Series[1]->Title = "New Title";
UniChart->SeriesList->Series[2]->Title = "New Title";

We will try to add this in future versions.

Link to comment
Share on other sites

31 minutes ago, Sherzod said:

Because for them there is only one series...

We will try to add this in future versions.

On my side I was using 3 x UniLineSeries and 3 x UniBarSeries, so its strange that it worked with UniLineSeries.

Thanks for trying to add support for UniChart->SeriesList->Series[0]->Title = "New Title";

Much appreciated! It's a pity though that we can't get SetTitle() to work for C++ as an interim solution. Not being able to change the title for a series is a showstopper for me right now.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...