Skip to content

Commit e930f50

Browse files
authored
Make readme comply with latest release again
Also improve the word about the samples and do some smaller changes
1 parent 5dbe2d3 commit e930f50

File tree

1 file changed

+44
-46
lines changed

1 file changed

+44
-46
lines changed

README.md

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -84,55 +84,51 @@ Then add a few `@using` statements
8484
@using ChartJs.Blazor.Util
8585
```
8686

87-
Below the `@using` statements add a `Chart` component
87+
Below the `@using` statements add a `ChartJsPieChart` component
8888
```html
89-
<Chart @ref="_pieChartJs"
90-
Config="@_config"
91-
TConfig="PieConfig"
92-
Width="600"
93-
Height="300"/>
89+
<ChartJsPieChart @ref="_pieChartJs" Config="@_config" Width="600" Height="300"/>
9490
```
95-
The last step is to make the `Chart` from above, reachable from your code to configure it and to give it some data to display. In the `@code` section of your .razor file create matching variables to reference the chart and its configuration. Finally, give your chart a title and some data. The finished code should look like this:
91+
The last step is to make the `ChartJsPieChart` from above, reachable from your code to configure it and to give it some data to display. In the `@code` section of your .razor file create matching variables to reference the chart and its configuration. Finally, give your chart a title and some data. The finished code should look like this:
9692

9793
```csharp
98-
private PieConfig _config;
99-
private Chart<PieConfig> _pieChartJs;
94+
private PieConfig _config;
95+
private ChartJsPieChart _pieChartJs;
10096

101-
protected override void OnInitialized()
97+
protected override void OnInitialized()
98+
{
99+
_config = new PieConfig
102100
{
103-
_config = new PieConfig
101+
Options = new PieOptions
104102
{
105-
Options = new PieOptions
103+
Title = new OptionsTitle
106104
{
107-
Title = new OptionsTitle
108-
{
109-
Display = true,
110-
Text = "Sample chart from Blazor"
111-
},
112-
Responsive = true,
113-
Animation = new ArcAnimation
114-
{
115-
AnimateRotate = true,
116-
AnimateScale = true
117-
}
105+
Display = true,
106+
Text = "Sample chart from Blazor"
107+
},
108+
Responsive = true,
109+
Animation = new ArcAnimation
110+
{
111+
AnimateRotate = true,
112+
AnimateScale = true
118113
}
119-
};
114+
}
115+
};
120116

121-
_config.Data.Labels.AddRange(new[] {"A", "B", "C", "D"});
117+
_config.Data.Labels.AddRange(new[] { "A", "B", "C", "D" });
122118

123-
var pieSet = new PieDataset
124-
{
125-
BackgroundColor = new[] { ColorUtil.RandomColorString(), ColorUtil.RandomColorString(), ColorUtil.RandomColorString(), ColorUtil.RandomColorString() },
126-
BorderWidth = 0,
127-
HoverBackgroundColor = ColorUtil.RandomColorString(),
128-
HoverBorderColor = ColorUtil.RandomColorString(),
129-
HoverBorderWidth = 1,
130-
BorderColor = "#ffffff",
131-
};
132-
133-
pieSet.Data.AddRange(new double[] {4, 5, 6, 7});
134-
_config.Data.Datasets.Add(pieSet);
135-
}
119+
var pieSet = new PieDataset
120+
{
121+
BackgroundColor = new[] { ColorUtil.RandomColorString(), ColorUtil.RandomColorString(), ColorUtil.RandomColorString(), ColorUtil.RandomColorString() },
122+
BorderWidth = 0,
123+
HoverBackgroundColor = ColorUtil.RandomColorString(),
124+
HoverBorderColor = ColorUtil.RandomColorString(),
125+
HoverBorderWidth = 1,
126+
BorderColor = "#ffffff",
127+
};
128+
129+
pieSet.Data.AddRange(new double[] { 4, 5, 6, 7 });
130+
_config.Data.Datasets.Add(pieSet);
131+
}
136132
```
137133

138134
**Breakdown**
@@ -141,9 +137,7 @@ First, in your `Index.html`/`_Host.cshtml` you've added references to static as
141137

142138
Then, you've imported `ChartJs.Blazor` in your `_Imports.razor`. The Blazor Team mentioned that this shouldn't be necessary in the future.
143139

144-
In your .razor file you added the `Chart` component and gave it some width and height. You specified that the component should use the variable `_config` as the chart's configuration object. You also told Blazor that you want a direct reference to the chart and that the reference should be saved in your `_pieChartJs` variable.
145-
146-
Note: for the moment you need to explicitly specify the type of the configuration object `TConfig="PieConfig"`. That won't be necessary in the future.
140+
In your .razor file you added the `ChartJsPieChart` component and gave it some width and height. You specified that the component should use the variable `_config` as the chart's configuration object. You also told Blazor that you want a direct reference to the chart and that the reference should be saved in your `_pieChartJs` variable.
147141

148142
When your page's `OnInitialized()` method is executed you're setting the chart's configuration and dataset to be displayed.
149143

@@ -246,17 +240,21 @@ When your page's `OnInitialized()` method is executed you're setting the chart's
246240
```
247241

248242
### Dig deeper
249-
For detailed instructions read the [Chart.Js](https://www.chartjs.org/docs/latest/charts/) documentation to understand how each chart works.
243+
For detailed instructions read the [Chart.js](https://www.chartjs.org/docs/latest/charts/) documentation to understand how each chart works.
250244
251245
## A word on the samples
252-
The **samples** folder contains three projects, one for a client-side Blazor app, another one for a server-side Blazor app and a shared project. The shared project is not really necessary but that is how I chose to avoid code duplication.
253246

254-
The documentation might lag the actual development state (who likes to write documentation, am I right?) but the samples will probably never lag the actual state of the library. This is due to the way in which I develop where I constantly run the samples to play with new features of ChartJs.
247+
#### The current samples are flawed in many ways. If you would like to help improving them, please see [this issue](https://github.com/mariusmuntean/ChartJs.Blazor/issues/122).
248+
249+
The **samples** folder contains three projects, one for a client-side Blazor app, another one for a server-side Blazor app and a shared project. The shared project is not really necessary but that is how we chose to avoid code duplication.
255250

256-
To make it easier for you to see what ChartJs.Blazor can do I host the client-side samples with [Netlify](https://www.netlify.com) on [www.iheartblazor.com](https://www.iheartblazor.com) (and a few other domains 😁)
251+
Unlike the documentation, the samples should always be up to date with the current development on master. That means, that the code you see in the samples folder on master might not actually compile on the current nuget version.
252+
To browse the samples for the latest nuget version, see the [samples on the releases branch](https://github.com/mariusmuntean/ChartJs.Blazor/tree/releases/samples).
257253
254+
To make it easier for you to see what ChartJs.Blazor can do, we host the client-side samples with [Netlify](https://www.netlify.com) on [www.iheartblazor.com](https://www.iheartblazor.com) (and a few other domains 😁).
255+
However, the demo page might lag behind a bit too so if you want to be sure, compile the [samples on the releases branch](https://github.com/mariusmuntean/ChartJs.Blazor/tree/releases/samples).
258256
259-
If you go there you should see something like this:
257+
If you go to the demo page, you should see something like this:
260258
![Charts](media/samples.gif)
261259

262260
# Contributors

0 commit comments

Comments
 (0)