Sherzod Posted February 20 Share Posted February 20 @Woutero Sorry I couldn't help you migrate your code from Delphi. But if this is acceptable for you, I will try to give you a temporary solution using a client side function. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted February 20 Share Posted February 20 @Woutero Another approach: 1. UniChart1.ClientEvents.ExtEvents -> function afterrender(sender, eOpts) { sender._setTitle = function() { var argsArray = Array.from(arguments); sender.chart.series[0].setTitle(argsArray); } } 2. Usage: procedure TMainForm.UniButton1Click(Sender: TObject); begin //Suppose we have two UniBarSeries: Series3 and Series6 Series6.Title := 'New title'; UniChart3.JSInterface.JSCall('_setTitle', [Series3.Title, Series6.Title]); end; Quote Link to comment Share on other sites More sharing options...
Woutero Posted February 20 Author Share Posted February 20 Sherzod Thanks, I will try the method above and report back. I was able to make some progress on the C++ code. The following C++ code for SetTitle compile under C++ Builder 10.4. 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 *BarSeries = new TUniBarSeries(AUniSeries->Parent); BarSeries = (TUniBarSeries *) AUniSeries->Parent->SeriesList->Series[I]; Titles = Titles + "\"" + BarSeries->Title + "\","; } Titles = RemoveTrailingChar(Titles, ','); // Up until here Titles agree with running in Delphi, yet series Titles are not updated on chart when the next line is executed AUniSeries->Parent->JSInterface->JSCall((UnicodeString)L"chart.series[0].setTitle",ARRAYOFCONST((Titles))); } } In debug mode, it generates exactly the same output in Titles when compared to running in Delphi. Yet, the labels are not updated on the chart. So we now only have one line of Delphi code that we need to get a working C++ translation. DELPHI: with AUniBarSeries.Parent.JSInterface do JSCall('chart.series[0].setTitle', [JSArray(Titles)]); C++: AUniSeries->Parent->JSInterface->JSCall((UnicodeString)L"chart.series[0].setTitle",ARRAYOFCONST((Titles))); 1 Quote Link to comment Share on other sites More sharing options...
Woutero Posted February 20 Author Share Posted February 20 4 hours ago, Sherzod said: 1. UniChart1.ClientEvents.ExtEvents -> function afterrender(sender, eOpts) { sender._setTitle = function() { var argsArray = Array.from(arguments); sender.chart.series[0].setTitle(argsArray); } } Sherzod When I use this code, it just hangs at startup of http://localhost:8077/ Do we use the ExtEvents script as is? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted February 20 Share Posted February 20 @Woutero What error are you seeing in the browser console? Quote Link to comment Share on other sites More sharing options...
Woutero Posted February 20 Author Share Posted February 20 Uncaught SyntaxError: Unexpected token ')' Quote Link to comment Share on other sites More sharing options...
Woutero Posted February 21 Author Share Posted February 21 Sherzod Good news, success! I had some time to double check everything. There was a } character missing in the afterrender event, causing the freeze. Finally I was able to display 3 new titles for a UniBarSeries using the C++ code UnicodeString TestStr1, TestStr2, TestStr3; TestStr1 = "Test1"; TestStr2 = "Test2"; TestStr3 = "Test3"; UniChart3->JSInterface->JSCall("_setTitle", ARRAYOFCONST((TestStr1,TestStr2,TestStr3))); No need for using SetTitle(). Thank so much, you're a genius! 1 Quote Link to comment Share on other sites More sharing options...
Sherzod Posted February 21 Share Posted February 21 Very good! Thanks. Quote Link to comment Share on other sites More sharing options...
Woutero Posted February 23 Author Share Posted February 23 Sherzod Your solution for the Titles is working like a charm, thanks. But how can I set the Stacked property of a UniBarSeries via the SeriesList? In other words if Series[0], Series[1] and Series[2] are all UniBarSeries, I want to do: UniChart1->SeriesList->Series[0]->Stacked = false; UniChart1->SeriesList->Series[1]->Stacked = false; UniChart1->SeriesList->Series[2]->Stacked = false; Quote Link to comment Share on other sites More sharing options...
Woutero Posted February 23 Author Share Posted February 23 Sherzod I was able to set the Stacked property for the underlying UniBarSeries using the following C++ procedure: void __fastcall TForm1::SetStacked(TUniChartSeries *AUniSeries, bool IsStacked) { int I; for (I=0; I<AUniSeries->Parent->SeriesList->Count; I++) { TUniBarSeries *BarSeries = new TUniBarSeries(AUniSeries->Parent); BarSeries = (TUniBarSeries *) AUniSeries->Parent->SeriesList->Series[I]; BarSeries->Stacked = IsStacked; } } But, the actual charts are not updated. So we are sitting with a similar problem as with Titles. I assume we will have to use an afterrender event to update the Stacked property of the UniBarSeries on the Chart? But how? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted February 23 Share Posted February 23 Hello, Try to use chart.redraw() on the client side. Quote Link to comment Share on other sites More sharing options...
Woutero Posted February 23 Author Share Posted February 23 As in JSInterface.JSCall('chart.redraw', []); Or within a Event? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted February 23 Share Posted February 23 2 minutes ago, Woutero said: UniChart1.JSInterface.JSCall('chart.redraw', []); Yes, try... Quote Link to comment Share on other sites More sharing options...
Woutero Posted February 23 Author Share Posted February 23 Sherzod No unfortunately it does not work. Even when I use UniBarSeries1->Stacked = true; UniBarSeries2->Stacked = true; UniBarSeries3->Stacked = true; it does not work. Only the original Stacked setting as per the UniBarSeries on the UniChart at design time is used. If I change the Stacked property at runtime, the UniChart does not use the new setting. Remember, I also cannot create Series dynamically in C++, I can only create Series upfront on the UniChart via design. Is there any way how one can set the Stacked setting during run time via JavaScript? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted February 23 Share Posted February 23 Hi, Do you have all series Stacked = False in designtime? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted February 23 Share Posted February 23 16 minutes ago, Woutero said: Is there any way how one can set the Stacked setting during run time via JavaScript? Try this approach: procedure TMainForm.UniButton1Click(Sender: TObject); begin UniChart1.JSInterface.JSCall('chart.series[0].setStacked', [False]); //True UniChart1.JSInterface.JSCallDefer('chart.redraw', [], 10); end; Quote Link to comment Share on other sites More sharing options...
Woutero Posted February 23 Author Share Posted February 23 Sherzod C++: bool tbool=False; UniChart1->JSInterface->JSCall("chart.series[0].setStacked", ((tbool))); works, thanks so much! 1 Quote Link to comment Share on other sites More sharing options...
Woutero Posted February 24 Author Share Posted February 24 Sherzod I need to change/increase the Bar width of bars in the series, at runtime. In another thread you provided a solution to set the MaxBarWidth via the beforeInit event: function chart.beforeInit(sender, config) { config.series[0].marker = false; config.series[0].renderer = function(a) { a.attr.maxBarWidth=10; }; But how can I set the BarWidth via a JSInterface.JSCall? Similar to UniChart1.JSInterface.JSCall('chart.series[0].setStacked', [False]); Quote Link to comment Share on other sites More sharing options...
Sherzod Posted February 24 Share Posted February 24 Hello, You can define a variable and change this variable also during runtime. Quote Link to comment Share on other sites More sharing options...
Woutero Posted February 24 Author Share Posted February 24 Thanks. Can you please give an example, so that I can see the correct syntax? Quote Link to comment Share on other sites More sharing options...
Woutero Posted February 24 Author Share Posted February 24 Sherzod I get a 'Cannot read properties of undefined (reading '0')' error when I use the code: UniChart1->ClientEvents->UniEvents: function beforeInit(sender, config) { config.series[0].renderer = function(a) { a.attr.maxBarWidth=50; }; } Quote Link to comment Share on other sites More sharing options...
Sherzod Posted February 24 Share Posted February 24 4 hours ago, Woutero said: function beforeInit(sender, config) First of all, this is the wrong place. 5 hours ago, Woutero said: Can you please give an example, so that I can see the correct syntax? I'll try to analyze. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted February 26 Share Posted February 26 On 2/24/2024 at 11:03 AM, Woutero said: But how can I set the BarWidth via a JSInterface.JSCall? Hello, I haven't found an easy way to do this. When the chart size is smaller, barWidth will still not be taken into account. What do you need this for? Quote Link to comment Share on other sites More sharing options...
Woutero Posted February 26 Author Share Posted February 26 Sherzod I simply want to make the chart looks better. Such narrow bars do not look right. Look at the same chart within VCL Delphi: The bars in Delphi are much wider which is proportional to the chart as a whole. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted February 26 Share Posted February 26 17 minutes ago, Woutero said: The bars in Delphi are much wider which is proportional to the chart as a whole. Okay. On 2/24/2024 at 12:00 PM, Woutero said: config.series[0].renderer = function(a) { a.attr.maxBarWidth=50; }; Then just set a large number, for example 1000 instead of 50. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.