Page 1 of 1
Set color gradient based on time series
Posted: Tue Jun 13, 2023 12:54 am
by 16487010
How do I automatically set a color gradient based on date. I want to be able to visually establish a how my data set may have changed through time, specifically in a triangular plot.
Re: Set color gradient based on time series
Posted: Tue Jun 13, 2023 12:35 pm
by yeray
Hello,
Could you please show us some image about what would you like to get?
Re: Set color gradient based on time series
Posted: Tue Jun 13, 2023 9:37 pm
by 16494103
Attached is a concept
Here is the code I am currently using
Code: Select all
/// This procedure relies on data in the FDMemTableTri to produce the Trilear
/// Chart. The user chooses three analytes from LookupList boxes and then uses
/// a RadioGroup Box to assign series based on Media, Sample Type, Location, etc.
/// FDMemTable is then indexed based on RadioGroup choice. The procedure then
/// runs through FDMemTableTri to get the data.
procedure TfmAnalyticalGraphs.FillTriPlotSeries;
Var
TriPlotSeries : TTernarySeries;
NameNew, NameOld: String; ///These variables are used to evaluate when the end of a series is reached, and then the name of the next series.
PStyle : TSeriesPointerStyle;
SeriesColor : TColor;
k, m : integer;
Begin
ChartTriPlot.SeriesList.Clear;
ChartTriPlot.Walls.Back.Hide;
ChartTriPlot.Gradient.Visible:=False;
ChartTriPlot.Color:=clWhite;
k := 0;
m := 0;
with TTernarySeries(ChartTriPlot.AddSeries(TTernarySeries)) do
begin
ShowInLegend:=False;
AddNull;
VertexTitles[0].Text := cxLookupComboBoxTriAnal2.EditText;
VertexTitles[1].Text := cxLookupComboBoxTriAnal3.EditText;
VertexTitles[2].Text := cxLookupComboBoxTriAnal1.EditText;
end;
///Set Index by Radio Group - These become the means of setting up series such as "By Media" or By "Sample Type".
///For example - "By Media" could produce four series called "Groundwater", "Soil", "Sediment", and "Surface Water"
FDMemTableTri.IndexesActive := False;
case cxRadioGroupTri.ItemIndex of
0 : FDMemTableTri.IndexFieldNames := 'Media_PK';
1 : FDMemTableTri.IndexFieldNames := 'Sample_Type_PK';
2 : FDMemTableTri.IndexFieldNames := 'Locations_PK';
3 : FDMemTableTri.IndexFieldNames := 'Sample_Event_PK';
4 : FDMemTableTri.IndexFieldNames := 'Sample_Date';
5 : FDMemTableTri.IndexFieldNames := 'Sample_Depth_Top';
6 : FDMemTableTri.IndexFieldNames := 'Inventory_PK';
7 : FDMemTableTri.IndexFieldNames := 'Sample_PK';
end;
FDMemTableTri.IndexesActive := True;
with FDMemTableTri do
begin
DisableControls;
try
First;
case cxRadioGroupTri.ItemIndex of
0 : NameNew := FDMemTableTriMEDIA.AsString;
1 : NameNew := FDMemTableTriSAMPLE_TYPE.AsString;
2 : NameNew := FDMemTableTriLOCATION.AsString;
3 : NameNew := FDMemTableTriSAMPLE_EVENT_NAME.AsString;
4 : NameNew := FDMemTableTriSAMPLE_DATE.AsString;
5 : NameNew := FDMemTableTriSAMPLE_DEPTH_TOP.AsString;
6 : NameNew := FDMemTableTriINVENTORY_NAME.AsString;
7 : NameNew := FDMemTableTriSAMPLE_NAME.AsString;
end;
while not(EOF) do
Begin
NameOld := NameNew;
with ChartTriPlot.AddSeries(TTernarySeries) as TTernarySeries do
begin
Title := NameOld;
UseColorRange:=False;
UsePalette:=False;
ColorEachPoint:=False;
pointer.Size := 10;
pointer.Visible := True;
case k of
0 : SeriesColor := clRed;
1 : SeriesColor := clBlue;
2 : SeriesColor := clLime;
3 : SeriesColor := clYellow;
4 : SeriesColor := clMaroon;
5 : SeriesColor := clTeal;
6 : SeriesColor := clFuchsia;
7 : SeriesColor := clBlack;
8 : SeriesColor := clAqua;
9 : SeriesColor := clNavy;
10 : SeriesColor := clGreen;
11 : SeriesColor := clPurple;
12 : SeriesColor := clGray;
13 : SeriesColor := clSilver;
14 : SeriesColor := clOlive;
15 : SeriesColor := clMoneyGreen;
16 : SeriesColor := clSkyBlue;
17 : SeriesColor := clMedGray;
end;
case m of
0 : PStyle := psDonut;
1 : PStyle := psRectangle;
2 : PStyle := psTriangle;
3 : PStyle := psDownTriangle;
4 : PStyle := psStar;
5 : PStyle := psDiamond;
6 : PStyle := psCross;
7 : PStyle := psDiagCross;
8 : PStyle := psLeftTriangle;
9 : PStyle := psRightTriangle;
10 : PStyle := psCircle;
end;
pointer.Style := PStyle;
pointer.Color := SeriesColor;
while NameOld = NameNew do
begin
if cxCheckBoxTriIgnoreND.Checked then //This is different than Cross Plot and Time Series. Here we assume a ND to be zero
AddXYZ(FindField('Analyte2Result').AsFloat, FindField('Analyte3Result').AsFloat, FindField('RESULT').AsFloat)
else //The fields listed below will be either the detected Result or 0
AddXYZ(FindField('Analyte2Result_ND').AsFloat, FindField('Analyte3Result_ND').AsFloat, FindField('RESULT_ND').AsFloat);
if Not (EOF) then
Begin
next;
case cxRadioGroupTri.ItemIndex of
0 : NameNew := FDMemTableTriMEDIA.AsString;
1 : NameNew := FDMemTableTriSAMPLE_TYPE.AsString;
2 : NameNew := FDMemTableTriLOCATION.AsString;
3 : NameNew := FDMemTableTriSAMPLE_EVENT_NAME.AsString;
4 : NameNew := FDMemTableTriSAMPLE_DATE.AsString;
5 : NameNew := FDMemTableTriSAMPLE_DEPTH_TOP.AsString;
6 : NameNew := FDMemTableTriINVENTORY_NAME.AsString;
7 : NameNew := FDMemTableTriSAMPLE_NAME.AsString;
end;
end
else
Break;
end;
inc(k);
if k = 18 then
begin
k := 0;
inc(m);
end;
end;
end;
finally
EnableControls;
end;
end;
end;
Re: Set color gradient based on time series
Posted: Wed Jun 14, 2023 7:09 am
by yeray
Hello,
I would use a
TTernarySeries
and use
ApplyBright
function to define the color of each point from the series base color and calculating the
HowMuch
argument (0-255) depending on the date, probably coming from the database.
- Project1_2023-06-14_09-09-10.png (28.72 KiB) Viewed 15566 times
Code: Select all
uses TeeTernary, TeCanvas;
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
Chart1.Align:=alClient;
Chart1.View3D:=False;
Chart1.Color:=clWhite;
Chart1.Gradient.Visible:=False;
Chart1.Walls.Back.Color:=clWhite;
Chart1.Walls.Back.Gradient.Visible:=False;
Chart1.Legend.Hide;
with TTernarySeries(Chart1.AddSeries(TTernarySeries)) do
begin
Pointer.Style:=psDonut;
Pointer.Size:=10;
UseColorRange:=False;
UsePalette:=False;
ColorEachPoint:=False;
FillSampleValues;
for i:=0 to Count-1 do
ValueColor[i]:=ApplyBright(Color, Round(random*255)); // change the second argument for a value date - dependant
end;
end;
Re: Set color gradient based on time series
Posted: Wed Jun 14, 2023 6:02 pm
by 16494103
Thanks for the advice. I couldn't find a lot of information for ApplyBright and have a question.
What are the range of integers allowed?
Re: Set color gradient based on time series
Posted: Wed Jun 14, 2023 7:16 pm
by yeray
Hello,
It allows 0 to 255.