Page 1 of 1

Map Series Demo Similar to Google Charts

Posted: Thu Jun 08, 2017 7:00 pm
by 16580573
Hello,

I am currently using Google Charts (https://developers.google.com/chart/int ... y/geochart) to draw a map chart, the example is very simple to setup, I am even using it in Delphi using TWebBrowser and TPageProducer.
I am trying to do the same in Delphi using TChart (for Offline clients), and I am facing the following difficulties:
1 - How to setup the values for the countries: The data I have is very simple, Country and a number (This should be the Z value in TChart), but I found that I have multiple countries in the data section, so if I have [USA, 30], how should I set this up?
2 - Hovering over a country should show a simple tooltip value (Country name and the value), my search lead me to .NET samples only so far
3 - One more question, do I need to supply any shape files (or manually add any resource files) to my VCL application to use the map series.
Any help or simple demo using one map series.

Re: Map Series Demo Similar to Google Charts

Posted: Fri Jun 09, 2017 8:17 am
by yeray
Hello,
nader wrote:1 - How to setup the values for the countries: The data I have is very simple, Country and a number (This should be the Z value in TChart), but I found that I have multiple countries in the data section, so if I have [USA, 30], how should I set this up?
Once a map is loaded, the series has a "Labels" array you can use to search for the index of a country. Then you can use that index to update the series MandatoryValueList array with the desired values.
Here a simple example:

Code: Select all

type
  TCountry = class
    Name: String;
    Value: Double;
  end;

implementation

{$R *.dfm}

uses TeeWorldSeries;

var MyCountries: array of TCountry;
    Series1: TWorldSeries;

procedure TForm1.FormCreate(Sender: TObject);
var i, j: Integer;
begin
  Chart1.View3D:=False;
  Chart1.Legend.Visible:=False;

  Series1:=TWorldSeries.Create(self);
  Chart1.AddSeries(Series1);

  Series1.Map:=TWorldMap(6);

  //populate array of countries with random values
  SetLength(MyCountries,16);
  j:=0;
  for i:=0 to Series1.Count-1 do
  begin
    if (j=0) or (MyCountries[j-1].Name<>Series1.Labels[i]) then
    begin
      MyCountries[j]:=TCountry.Create;
      MyCountries[j].Name:=Series1.Labels[i];
      MyCountries[j].Value:=random*20;
      Inc(j);
    end;
  end;
end;

//use array of countries to populate series
procedure TForm1.Button1Click(Sender: TObject);
var i, j: Integer;
begin
  for i:=0 to Series1.Count-1 do
  begin
    for j:=0 to High(MyCountries) do
    begin
      if Series1.Labels[i]=MyCountries[j].Name then
      begin
        Series1.MandatoryValueList[i]:=MyCountries[j].Value;
        break;
      end;
    end;
  end;

  Chart1.Repaint;
end;
nader wrote:2 - Hovering over a country should show a simple tooltip value (Country name and the value), my search lead me to .NET samples only so far
You can use the TMarksTipTool. This adds the tool and sets it to show both the label and the value:

Code: Select all

(Chart1.Tools.Add(TMarksTipTool) as TMarksTipTool).Style:=smsLabelValue;
nader wrote:3 - One more question, do I need to supply any shape files (or manually add any resource files) to my VCL application to use the map series.
You can either use any of the maps included with TeeChart or you can load your shape files.
Take a look at the TeeMaps demo included with the installation in the "\Examples\TeeMaps" folder.

Re: Map Series Demo Similar to Google Charts

Posted: Fri Jun 09, 2017 6:19 pm
by 16580573
Thank you,

Actually I came here to answer my own question ;)
I figured it out, and I have an identical chart to what is offered by Google running offline, Awesome!

The only suggestion I have is related to the country name, it is better to have support for ISO country codes.

Thank you so much :)

Nader

Re: Map Series Demo Similar to Google Charts

Posted: Fri Jun 09, 2017 6:54 pm
by 16580573
I found the code too as part of the Shape object :)

Thanks

Re: Map Series Demo Similar to Google Charts

Posted: Mon Jun 12, 2017 6:27 am
by yeray
Hello,

I'm glad to hear all works as desired! :)