class TestDoughnutChart(DoughnutChart):
"""
Test doughnut chart with ChartJS.
"""
#: Whether to show the legend.
legend = True
#: The position of the legend.
legend_position = "right"
#: Whether to color the chart.
color = False
def get_categories(self) -> list[str]:
"""
Return names of categories.
Returns:
A list of names of categories.
"""
return ["January", "February", "March", "April", "May", "June", "July"]
def get_dataset(self) -> list[int]:
"""
Return a dataset.
Returns:
A list of values for the dataset.
"""
return [75, 44, 92, 11, 44, 95, 53]
class TestChart(StackedBarChart):
"""
Test chart with ChartJS.
"""
def get_categories(self) -> list[str]:
"""
Return 7 labels for the x-axis.
Returns:
A list of 7 labels for the x-axis.
"""
return ["January", "February", "March", "April", "May", "June", "July"]
def get_dataset_labels(self) -> list[str]:
"""
Return names of datasets.
Returns:
A list of names of datasets.
"""
return [
"Central",
"Eastside",
"Westside",
"Central2",
"Eastside2",
"Westside2",
"Central3",
"Eastside3",
"Westside3",
]
def get_datasets(self) -> list[list[float]]:
"""Return 3 datasets to plot."""
return [
[750, 440, 920, 1100, 440, 950, 350],
[410, 1920, 180, 300, 730, 870, 920],
[870, 210, 940, 3000, 900, 130, 650],
[750, 440, 920, 1100, 440, 950, 350],
[410, 920, 180, 2000, 730, 870, 920],
[870, 210, 940, 300, 900, 130, 650],
[750, 440, 920, 1100, 440, 950, 3500],
[410, 920, 180, 3000, 730, 870, 920],
[870, 210, 940, 300, 900, 130, 650],
]
def get_widget(self) -> HorizontalStackedBarChart:
"""
Return the horizontal bar chart.
Returns:
The horizontal bar chart.
"""
barchart = HorizontalStackedBarChart(
title="Formage Through July",
money=True,
legend=True,
width="500",
color=False,
)
barchart.set_categories(
["January", "February", "March", "April", "May", "June", "July"]
)
barchart.add_dataset([75, 44, 92, 11, 44, 95, 35], "Central")
barchart.add_dataset([41, 92, 18, 35, 73, 87, 92], "Eastside")
barchart.add_dataset([87, 21, 94, 13, 90, 13, 65], "Westside")
return barchart
class TestHorizontalHistogram(HorizontalHistogram):
"""
Test horizontal histogram with ChartJS.
"""
#: Whether to color the chart.
color = False
def load(self) -> None:
"""
Load the histogram data.
"""
mu = 100
sigma = 30
nums = []
bin_count = 50
for _ in range(10000):
temp = random.gauss(mu, sigma)
nums.append(temp)
self.build(nums, bin_count)