Hi
JQPlot works with json data.
But the demo is working with json as plain strings:
- Code: Select all
IWCGJQPlot2.JQPlotData := '[[[''Heavy Industry'', 12],[''Retail'', 9], [''Light Industry'', 14],[''Out of home'', 16],' +
'[''Commuting'', 7],[''Orientation'', 9]]]';
Which are not very workable.
So, assuming that in
"Label" (string) and "Value" (Currency).
"Value" has already the percentage, here's how you can do it:
- Code: Select all
uses
IWCGJSSuperObject;
procedure TIWJQPlotFrame.SetPieDonut;
var
LabelField: TField;
ValueField: TField;
PlotData: ISuperObject;
LayerData: ISuperObject;
SerieData: ISuperObject;
begin
PlotData:= SA([]);
LayerData:= SA([]);
LabelField:= myDataSet.FieldByName('Label');
ValueField:= myDataSet.FieldByName('Value');
myDataSet.DisableControls;
try
myDataSet.First;
while not myDataSet.Eof do
begin
SerieData:= SA([]);
SerieData.AsArray.Add(SO(LabelField.AsString));
SerieData.AsArray.Add(SO(ValueField.AsFloat));
LayerData.AsArray.Add(SerieData);
myDataSet.Next;
end;
finally
myDataSet.EnableControls;
end;
PlotData.AsArray.Add(LayerData);
IWCGJQPlot1.JQPlotData := PlotData.AsJSon;
// Random options
IWCGJQPlot1.JQPlotOptions.SeriesDefaults.Renderer:= jqprPieRenderer;
IWCGJQPlot1.JQPlotOptions.SeriesDefaults.PieRendererOptions.ShowDataLabels:= True;
IWCGJQPlot1.JQPlotOptions.Legend.Show:= True;
IWCGJQPlot1.JQPlotOptions.Legend.Location:= jqpooE;
end;