mirror of
https://github.com/Relintai/pandemonium_engine_easy_charts.git
synced 2024-11-20 10:47:22 +01:00
➕ BarChart example
This commit is contained in:
parent
b0e786f553
commit
5d18535a3e
52
addons/easy_charts/examples/bar_chart/Control.gd
Normal file
52
addons/easy_charts/examples/bar_chart/Control.gd
Normal file
@ -0,0 +1,52 @@
|
||||
extends Control
|
||||
|
||||
onready var chart: BarChart = $BarChart
|
||||
|
||||
func _ready():
|
||||
# Let's create our @x values
|
||||
var x: Array = ["Day 1", "Day 2", "Day 3", "Day 4", "Day 5"]
|
||||
# And our y values. It can be an n-size array of arrays.
|
||||
# NOTE: `x.size() == y.size()` or `x.size() == y[n].size()`
|
||||
var y: Array = [
|
||||
[20, 10, -15, 30, 42],
|
||||
[10, 1, -5, 20, 32]
|
||||
]
|
||||
|
||||
# Add some labels for the x axis, we don't want to use our x values array
|
||||
# they will be printed on the chart ticks instead of the value of the x axis.
|
||||
var x_labels: Array = ArrayOperations.suffix(x, "s")
|
||||
|
||||
# Let's customize the chart properties, which specify how the chart
|
||||
# should look, plus some additional elements like labels, the scale, etc...
|
||||
var cp: ChartProperties = ChartProperties.new()
|
||||
cp.grid = true
|
||||
cp.title = "Air Quality Monitoring"
|
||||
cp.x_label = ("Days")
|
||||
cp.x_scale = 20
|
||||
cp.y_label = ("Sensor values")
|
||||
cp.y_scale = 10
|
||||
cp.points = false
|
||||
cp.interactive = true # false by default, it allows the chart to create a tooltip to show point values
|
||||
# and interecept clicks on the plot
|
||||
|
||||
# Set the x_labels
|
||||
# $LineChart.x_labels = x_labels
|
||||
|
||||
# Plot our data
|
||||
chart.plot(x, y, cp)
|
||||
|
||||
# Uncommenting this line will show how real time data plotting works
|
||||
set_process(false)
|
||||
|
||||
func _process(delta: float):
|
||||
# This function updates the values of chart x, y, and x_labels array
|
||||
# and updaptes the plot
|
||||
var new_val: String = "Day %s" % (chart.x.size() + 1)
|
||||
chart.x.append(new_val)
|
||||
chart.y[0].append(randi() % 40)
|
||||
chart.y[1].append(randi() % 50)
|
||||
chart.update()
|
||||
|
||||
|
||||
func _on_CheckButton_pressed():
|
||||
set_process(not is_processing())
|
49
addons/easy_charts/examples/bar_chart/Control.tscn
Normal file
49
addons/easy_charts/examples/bar_chart/Control.tscn
Normal file
@ -0,0 +1,49 @@
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://addons/easy_charts/control_charts/BarChart/bar_chart.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://addons/easy_charts/examples/bar_chart/Control.gd" type="Script" id=2]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id=1]
|
||||
content_margin_right = 5.0
|
||||
content_margin_bottom = 5.0
|
||||
draw_center = false
|
||||
border_width_right = 2
|
||||
border_width_bottom = 2
|
||||
border_color = Color( 0, 0, 0, 1 )
|
||||
|
||||
[node name="Control" type="Control"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
script = ExtResource( 2 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": true
|
||||
}
|
||||
|
||||
[node name="BarChart" parent="." instance=ExtResource( 1 )]
|
||||
|
||||
[node name="CheckButton" type="CheckButton" parent="."]
|
||||
margin_right = 223.0
|
||||
margin_bottom = 40.0
|
||||
custom_colors/font_color_disabled = Color( 0, 0, 0, 1 )
|
||||
custom_colors/font_color_focus = Color( 0, 0, 0, 1 )
|
||||
custom_colors/font_color_hover_pressed = Color( 0, 0, 0, 1 )
|
||||
custom_colors/font_color = Color( 0, 0, 0, 1 )
|
||||
custom_colors/font_color_hover = Color( 0, 0, 0, 1 )
|
||||
custom_colors/font_color_pressed = Color( 0, 0, 0, 1 )
|
||||
text = "Start Relatime Plotting"
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
anchor_left = 1.0
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = -159.0
|
||||
margin_top = -19.0
|
||||
custom_colors/font_color = Color( 0, 0, 0, 1 )
|
||||
custom_styles/normal = SubResource( 1 )
|
||||
text = "Try to scale the window!"
|
||||
__meta__ = {
|
||||
"_edit_lock_": true
|
||||
}
|
||||
|
||||
[connection signal="pressed" from="CheckButton" to="." method="_on_CheckButton_pressed"]
|
Loading…
Reference in New Issue
Block a user