سؤال

ANSWER

Thanks Filip, finally I found way to set the color. I just need to add Background property in DataPointStyle. I am posting my answer here. Also found a way how to modify the default tooltip.

Showing lines with different colors on a Silverlight Toolkit’s LineChart?

Using a custom ToolTip in Silverlight charting

<charting:LineSeries.DataPointStyle>
    <Style TargetType="charting:LineDataPoint">
        <Setter Property="Width" Value="17" />
        <Setter Property="Height" Value="17" />
        <Setter Property="Background" Value="Lime"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="charting:LineDataPoint">
                    <Grid>
                        <ToolTipService.ToolTip>
                            <ContentControl Content="{Binding Value,Converter={StaticResource MyConv},ConverterParameter=TEST}"/>
                        </ToolTipService.ToolTip>
                        <Ellipse Fill="Lime" Stroke="Lime" StrokeThickness="3" />
                    </Grid>
                </ControlTemplate>

            </Setter.Value>
        </Setter>
    </Style>
</charting:LineSeries.DataPointStyle>

Question 1

I am creating multiple line chart series in a chart. Now WinRT XAML Toolkit assigns color for each series in random manner. I am using custom style for data points, so when I use custom style that randomness of color goes off. So how can I set or get that random color of series ? If I can get the color then I can use that color in datapoint, and if I can set color then I will generate random color myself.

Question 2

Moreover while hovering over data points the tool tip shows the dependent value, but I want to show more details how can I achieve that ?

Here's my code with custom style.

<charting:Chart x:Name="LineChart" Title="Line Chart" Margin="70,0">
    <charting:LineSeries
                Title="Population 1"
                IndependentValueBinding="{Binding Name}"
                DependentValueBinding="{Binding Value}"
                IsSelectionEnabled="True">
            <charting:LineSeries.DataPointStyle>
                <Style TargetType="charting:LineDataPoint">
                    <Setter Property="Width" Value="17" />
                    <Setter Property="Height" Value="17" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="charting:LineDataPoint">
                                <Ellipse Fill="Green" Stroke="Green" StrokeThickness="3" />
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </charting:LineSeries.DataPointStyle>
        </charting:LineSeries>

    <charting:LineSeries
            Title="Population 2"
            IndependentValueBinding="{Binding Name}"
            DependentValueBinding="{Binding Value}"
            IsSelectionEnabled="True" Foreground="Blue">
        <charting:LineSeries.DataPointStyle>
            <Style TargetType="charting:LineDataPoint">
                <Setter Property="Width" Value="17" />
                <Setter Property="Height" Value="17" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="charting:LineDataPoint">
                            <Ellipse Fill="Red" Stroke="Red" StrokeThickness="3" />
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </charting:LineSeries.DataPointStyle>
    </charting:LineSeries>
</charting:Chart>

Chart with random color (NO CUSTOM DATAPOINT STYLE)

enter image description here

Chart with NO random color (WITH CUSTOM DATAPOINT STYLE) [You can see both line has yellow color]

enter image description here

هل كانت مفيدة؟

المحلول

Trying to Bing for silverlight toolkit chart custom line color yields some potentially useful pages, like this. It should work mostly the same with the WinRT XAML Toolkit, but where they customize the Silverlight-based templates - you would need to customize the WinRT XAML Toolkit-based ones that you can either try to extract with Blend/Visual Studio designer or get the original templates from the source that you can grab from CodePlex.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top